【问题标题】:@refreshScope Spring cloud config doesn't refresh application.properties value@refreshScope Spring 云配置不刷新 application.properties 值
【发布时间】:2021-01-02 23:39:57
【问题描述】:

我尝试在我的休息控制器上使用注解@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'

谢谢大家

【问题讨论】:

    标签: java spring spring-boot-actuator spring-cloud-config


    【解决方案1】:

    解决了。

    我将我的应用程序名称文件(客户端)从 application.yml 更改为 bootstrap.yml

    现在当我运行 localhost:8081/actuator/refresh 时,我得到了这个响应

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

    谢谢大家

    【讨论】:

      猜你喜欢
      • 2016-08-06
      • 2017-07-15
      • 2016-05-21
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-05-02
      • 2018-11-29
      • 2023-03-25
      相关资源
      最近更新 更多