수동으로 클라이언트 구성 내용을 새로 고침
증가 클라이언트 프로젝트 종속성
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
클라이언트 프로젝트는 구성 파일을 수정하는 방법
增加 management.endpoints.web.exposure.include = 새로 고침, 건강, 정보
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
추가 지원은 클라이언트 프로그램 노트를 새로 고치려면
구성 센터 클래스를 사용하여 @RefreshScope 노트를 추가 :
@RestController
//刷新触发地址/actuator/refresh
@RefreshScope
public class ConfigTestController {
//配置信息通过@Value注解读取,配置项用${配置项}读取
@Value("${bluersw.config}")
private String configBluersw;
@RequestMapping("/ConfigTest")
public String ConfigTest(){
return this.configBluersw;
}
}
테스트 결과 새로 고침
테스트-5 밖의 힘내웨어 하우스 구성 변경 내용 (bluersw.config = 시험-5), 클라이언트 프로그램 (봄 - 클라우드 - 설정 - 클라이언트), 클라이언트, 연구 결과는 보여 페이지 127.0.0.1:9006/ConfigTest를 새로 시작 콘텐츠 또는 테스트 -3-라면, 실행 :
curl -X POST http://127.0.0.1:9006/actuat/refresh
다시 페이지를 새로 고침 127.0.0.1:9006/ConfigTest, 페이지 내용은 테스트-5, 지침은 최신 값을 읽어 클라이언트 프로그램의 정보를 구성하기로 나타납니다.