Bootstrap 配置不生效问题
最近项目组在搭建环境,用的版本Spring Boot 2.5.x 版本
在集成Nacos 服务的时候,发现bootstrap.properties 配置不生效
一直读取application.yml 配置 此时的我…
经过多次查找方案,定位到问题
解决方案
经过测试
Spring Boot 版本 小于 2.4.0 版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
Spring Boot 版本 大于 2.4.0 版本,添加以下依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
除此之外要注意一个非常关键的问题点!!!!就是版本,如果你当前项目是已经引用Cloud结构需要检查 你当前boot 版本是否匹配 你的Cloud 版本
参考 Spring,IO 官网
否则 会出现如下报错:
- Change Spring Boot version to one of the following versions [2.3.x, 2.4.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]
当前boot 项目版本 2.5.x 版本 ,引用的3.0.3 或者大家去maven存储库查找一下
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.3</version>
</dependency>
配置完成以后,即可正常使用