springboot 集成 nacos

1、报错:required a bean of type 'org.springframework.cloud.alibaba.nacos.NacosConfigProperties' that could not be found.

      

***************************
APPLICATION FAILED TO START
***************************

Description:

Field nacosConfigProperties in org.springframework.cloud.alibaba.nacos.endpoint.NacosConfigEndpointAutoConfiguration required a bean of type 'org.springframework.cloud.alibaba.nacos.NacosConfigProperties' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'org.springframework.cloud.alibaba.nacos.NacosConfigProperties' in your configuration.

原因是 nacos的配置信息只能放在bootstrap.properties 才生效

 2、服务启动后能获取到nacos中配置的信息,但是nacos中更新后,服务获取的还是旧的值

      解决:网上查了各种说法,都没解决问题,最后nacos官网文档中的示例代码,而且是2年前的,下载下来改下配置,一运行就可以了,

 

 

 

经对比发现自己demo里 

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>0.2.1.RELEASE</version>
</dependency>

这个依赖是0.2.0 ,的,改成示例里的0.2.1 的就可以了,,目前发现最新的2.2.2,改成2.2.2的版本也是可以的
那根本的原因其实就是版本的问题,nacos的官方文档中有说明,

 


posted @ 2021-03-23 14:42  飞叶-枯寂  阅读(490)  评论(0编辑  收藏  举报