* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████ ┃+
* ┃ ┃ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃
* ┃ ┃ + + + +
* ┃ ┃
* ┃ ┃ + 神獸保佑
* ┃ ┃ 代碼無bug
* ┃ ┃ +
* ┃ ┗━━━┓ + +
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
問題描述
產(chǎn)生問題的原因是bootstrap.properties比application.properties的優(yōu)先級要高
由于bootstrap.properties是系統(tǒng)級的資源配置文件,是用在程序引導(dǎo)執(zhí)行時更加早期配置信息讀?。?br> 而application.properties是用戶級的資源配置文件,是用來后續(xù)的一些配置所需要的公共參數(shù)。
但是在SpringCloud 2020.* 版本把bootstrap禁用了,導(dǎo)致在讀取文件的時候讀取不到而報錯,所以我們只要把bootstrap重新導(dǎo)入進來就會生效了。
解決方法
方式一:添加配置
在yml或properties中添加如下配置文章來源:http://www.zghlxwxcb.cn/news/detail-743912.html
properties中添加
spring.cloud.nacos.config.import-check.enabled=false
yml中添加
spring:
cloud:
nacos:
config:
import-check:
enabled: false
方式二:添加pom
<!--開啟Spring Cloud 應(yīng)用程序啟動時加載bootstrap配置文件-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.4</version>
</dependency>
希望看到這篇文章的小伙伴都能解決bug文章來源地址http://www.zghlxwxcb.cn/news/detail-743912.html
到了這里,關(guān)于Add a spring.config.import=nacos: property to your configuration. If configuration is not required的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!