1、在集成Nacos配置中心时报如下错误:
xyAdmin- 2025-02-05 23:15:36 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
No spring.config.import property has been defined
Action:
Add a spring.config.import=nacos: property to your configuration.
If configuration is not required add spring.config.import=optional:nacos: instead.
To disable this check, set spring.cloud.nacos.config.import-check.enabled=false.
2、添加如下依赖,确定是否已经添加以下依赖。
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3、还有一个可能是配置的内容没有放到该文件中bootstrap.yml (切记重要),还有路径是否符合springboot的配置加载顺序。
这个是一个非常恶心的原因,一定要把配置nacos的配置文件放到这个文件里面,他的读取顺序才会覆盖默认的配置。如果没有放到该文件中,一直报找不到配置文件,错误日志如下
xyAdmin- 2025-02-06 00:38:33 [main] WARN c.a.c.n.c.NacosPropertySourceBuilder - Ignore the empty nacos configuration and get it based on dataId[service-system] & group[DEFAULT_GROUP]
xyAdmin- 2025-02-06 00:38:34 [main] WARN c.a.c.n.c.NacosPropertySourceBuilder - Ignore the empty nacos configuration and get it based on dataId[service-system.properties] & group[DEFAULT_GROUP]
xyAdmin- 2025-02-06 00:38:34 [main] WARN c.a.c.n.c.NacosPropertySourceBuilder - Ignore the empty nacos configuration and get it based on dataId[service-system-dev.properties] & group[DEFAULT_GROUP]
xyAdmin- 2025-02-06 00:38:34 [main] INFO o.s.c.b.c.PropertySourceBootstrapConfiguration - Located property source: [BootstrapPropertySource {name='bootstrapProperties-service-system-dev.properties,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-service-system.properties,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-service-system,DEFAULT_GROUP'}]
xyAdmin- 2025-02-06 00:38:34 [main] INFO com.tzy.trms.AppRun - The following 1 profile is active: "dev"

4、检查nacos配置文件是否符合配置文件规则
默认位置:在src/main/resources目录下。
优先级:Spring Boot会按照以下顺序加载配置文件:
bootstrap.properties 或 bootstrap.yml(如果存在)
application.properties 或 application.yml(如果存在)
如果是yaml,在nacos中的data-id一定要加上.yaml后缀,因为读取的默认规则是application.name+dev+.yaml。
${prefix}-${spring.profiles.active}.${file-extension}
${prefix} 通常是你的项目名或者服务名。
${spring.profiles.active} 是 Spring 的环境配置标识,例如 dev、test、prod 等。
${file-extension} 是文件扩展名,通常是 properties 或 yaml。
3、问题解决
2万+

被折叠的 条评论
为什么被折叠?



