小工具知识网

当前位置: 首页 > 行业知识 > Add a spring.config.import=nacos: property to your configuration.If configuration is not required

行业知识

Add a spring.config.import=nacos: property to your configuration.If configuration is not required

2026-11-06 19:43:52 来源:互联网转载

问题描述

产生问题的原因是bootstrap.properties比application.properties的优先级要高

由于bootstrap.properties是系统级的资源配置文件,是用在程序引导执行时更加早期配置信息读取;

而application.properties是用户级的资源配置文件,是用来后续的一些配置所需要的公共参数。

但是在SpringCloud 2020.* 版本把bootstrap禁用了,导致在读取文件的时候读取不到而报错,所以我们只要把bootstrap重新导入进来就会生效了。

在yml或properties中添加如下配置

properties中添加

spring.cloud.nacos.config.import-check.enabled=false

yml中添加

spring:    cloud:        nacos:            config:                import-check:                    enabled: false

完美解决

分界线------------------------------------------------------------------------------------------------------------------------

加上配置后发现启动后用Nacos配置中心会没有响应,

但是如果加上一个依赖不仅能解决之前的问题,还能够解决配置中心未响应的问题

                            org.springframework.cloud            spring-cloud-starter-bootstrap            3.1.4        

加上依赖后运行就能够看到加载配置资源

完美解决!!!!

上一篇:怎么测试忙线服务器?

下一篇:VB财务源码深度解析,揭秘财务管理的核心功能之源!