如何解决@refreshScope Spring 云配置不会刷新 application.properties 值
我尝试在我的休息控制器上使用注释@RefreshScope:
@RestController
@RefreshScope
public class SpringCloudControllerTest {
@Value("${data}")
private String value;
@GetMapping
public ResponseEntity<String> testPropertiesFile(){
return ResponseEntity.ok(value);
}
@Value 注释指的是我远程存储库上的 application.properties:
management.endpoints.web.exposure.include=*
data=2
如果我以这种方式更改我的文件:
management.endpoints.web.exposure.include=*
data=3
并在我的客户端运行请求 http://localhost:8081/actuator/refresh 回应只是:
[
"config.client.version"
]
如果我运行请求,我没有看到任何关于我的更改的响应
localhost:8081
响应总是“2”
这些是我对客户端的依赖:
compile group: 'org.springframework.cloud',name: 'spring-cloud-starter-config',version: '2.2.6.RELEASE'
compile group: 'org.springframework.boot',name: 'spring-boot-starter-actuator',version:'2.3.7.RELEASE'
谢谢大家
解决方法
解决了。
我将我的应用程序名称文件(客户端)从 application.yml 更改为 bootstrap.yml
现在当我运行 localhost:8081/actuator/refresh 时,我得到了这个响应
[
"config.client.version","data","spring.cloud.bootstrap.enabled"
]
谢谢大家
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。