Spring Boot 2.4版本開始,配置文件加載方式進行了重構(gòu),只會識別application.* 配置文件,并不會自動識別bootstrap.yml;
因此如果springboot工程引入的是2.4以上的版本,則在resource下配置文件為application.yml
如果寫入bootstrap.yml則不生效,顯示為如下:
解決方案:
方案一:spring-boot-starter-parent依賴降級,降到2.4以下版本;
方案二:resource下寫application.yml,不寫bootstrap.yml
方案三:在pom.xml中引入如下依賴,并在啟動類上添加注解@EnableDiscoveryClient
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
文章來源:http://www.zghlxwxcb.cn/news/detail-724526.html
優(yōu)先級問題:
對于常說的bootstrap.yml優(yōu)先級高于application.yml,這種是基于springcloud項目的基礎(chǔ)上,因SpringCloud是基于SpringBoot構(gòu)建的,所有SpringCloud項目兩種文件都會識別,這個時候才有優(yōu)先級的說法;文章來源地址http://www.zghlxwxcb.cn/news/detail-724526.html
到了這里,關(guān)于Springboot項目bootstrap.yml不生效問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!