springboot+springcloudnacos的服务,配置中心里加了个admin=true/false的配置,spring.cloud.nacos.config.refresh-enabled=true,本以为改了配置中心,再次访问接口就能生效,没想到并没有。
解决方法:
在使用@Value的类上,加注解@RefreshScope
再次刷新,就是最新配置。
注:没有加@RefreshScope时,Refresh keys changed: [isadmin]依然会打印,但是不起作用。
在网上搜索了下原因,有人说nacos1.3.0以下版本就没有这样的问题,不加@RefreshScope也能起作用,可能是nacos的bug,但是Nacos的官方文档里就已经明确写了:通过 Spring Cloud 原生注解 @RefreshScope 实现配置自动更新。见Nacos官方文档