alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
28k stars 8.34k forks source link

Using @RefreshScope in nacos cannot refresh the remote configuration file #3663

Closed hxm2234098193 closed 8 months ago

hxm2234098193 commented 8 months ago

I use @RefreshScope in nacos but cannot refresh the remote configuration file. I wrote a controller and used the @Value annotation to inject the test.token property in the configuration file.When I start the springboot project, I can get the test.token attribute value when I access the api. But when I modified the nacos configuration file, the results of my access to the API again were not updated.

This is the controller I wrote:

1711091381847

This is the configuration file for test.token on the nacos server:

1711091739717

This is the result of accessing the API in the browser: 1711091656660

But when I modified the configuration file in the nacos service and accessed the API again, the attribute value of test.token did not change, and there was no real-time refresh effect.

The configuration file after modifying test.token on the nacos server:

1711091941067

This is the result of accessing the API in the browser (not change): 1711091656660

This is the configuration file of springboot:

1711092060962 1711092089490

hxm2234098193 commented 8 months ago

springboot and springcloudalibaba 's version 1711094396607

hxm2234098193 commented 8 months ago

nacos version : 2.1.2

hxm2234098193 commented 8 months ago

After I changed application.yml to bootstrap.yml, the function became normal!

yuluo-yx commented 8 months ago

you can refer https://sca.aliyun.com/zh-cn/docs/2022.0.0.0/user-guide/nacos/advanced-guide#nacos-%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E8%BF%9B%E9%98%B6%E6%8C%87%E5%8D%97

dongguo4812 commented 7 months ago

https://github.com/alibaba/spring-cloud-alibaba/blob/2022.x/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.yaml 我看到 - nacos:nacos-config-example.properties?refresh=true,我这样配置 - optional:nacos:${spring.application.name}-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}?refresh=true测试是可以的