Manually refresh the client configuration content
Increased client project dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Client project to modify the configuration file
增加management.endpoints.web.exposure.include=refresh,health,info
spring.application.name=spring-cloud-config-client
server.port=9006
spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500
#设置不需要注册到 consul 中
spring.cloud.consul.discovery.register=false
#显示的暴露接入点
management.endpoints.web.exposure.include=refresh,health,info
Added support to refresh the client program notes
Add @RefreshScope notes on using the configuration center class:
@RestController
//刷新触发地址/actuator/refresh
@RefreshScope
public class ConfigTestController {
//配置信息通过@Value注解读取,配置项用${配置项}读取
@Value("${bluersw.config}")
private String configBluersw;
@RequestMapping("/ConfigTest")
public String ConfigTest(){
return this.configBluersw;
}
}
Refresh test results
The Git warehouse configuration change content outside Test-5 (bluersw.config = Test-5), start the client program (spring-cloud-config-client), the client refresh the page 127.0.0.1:9006/ConfigTest, findings show content or Test-3, then execute:
curl -X POST http://127.0.0.1:9006/actuat/refresh
127.0.0.1:9006/ConfigTest refresh the page again, the page content appears as Test-5, instructions to configure the information in the client program reads the latest value.