@refreshscope spring cloud config不刷新application.properties值

k2arahey  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(410)

我尝试在我的rest控制器上使用注解@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/执行器/刷新响应只是:

[
 "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'

谢谢大家

ztigrdn8

ztigrdn81#

解决了的。
我将应用程序名文件(客户端)从application.yml更改为bootstrap.yml
现在当我跑的时候localhost:8081/actuator/refresh 我得到了这个答复

[
"config.client.version",
"data",
"spring.cloud.bootstrap.enabled"
]

谢谢大家

相关问题