使用nacos做配置中心,但是程序启动失败,没有拉取配置中心的配置信息。检查之后发现是bootstrap.yml文件没有被加载,在项目的pom.xml文件中添加如下依赖,可能需要添加版本号,具体版本号可以去maven仓库查询,我使用的是 3.0.1
版本。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
重新导入依赖,然后重启项目,在项目日志里可以看到下面这一段信息,并且服务正常启动成功,说明服务启动成功。
2021-03-07 22:47:10.953 INFO 54020 --- [ restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-xxx-xxx-dev.yml,dev'}, BootstrapPropertySource {name='bootstrapProperties-xxx-xxx.yml,dev'}, BootstrapPropertySource {name='bootstrapProperties-xxx-xxx,dev'}]