구성 서버에서 spring-cloud를 사용하고 있습니다. 다시 시작하지 않고도 앱의 구성을 새로 고침하고 싶습니다. application.yml에서경로 새로 고침 내에서 구성 새로 고침이 작동하지 않습니다.
1) 단일 구성, 클라이언트 및 주석 @RefreshScope에 자식
job:
demo:
testMessage: 'My ID is 123'
2) 액추에이터에 저장 :
이
내 시나리오입니다 컨트롤러에서. 봄과 통합@RefreshScope
@Component
@RestController
public class DemoController {
@Value("${job.demo.testMessage}")
String testMessage;
@RequestMapping(value = "/", produces = "application/json")
public List<String> index() {
List<String> env = Arrays.asList(
"config 1 is: " + testMessage
);
return env;
}
}
3) 하나의 흐름 :
@RefreshScope
@Slf4j
@Setter
@Component
@ConfigurationProperties(prefix = "job.demo")
public class DemoFlow {
private String testMessage;
@Bean
public IntegrationFlow putDemoModelFlow() {
return IntegrationFlows.from(Http.inboundChannelAdapter("/demoFlow"))
.handle(new DemoHandler())
.handle(m -> log.info("[LOGGING DEMO] {}" , m.getPayload()))
.get();
}
private class DemoHandler implements GenericHandler {
@Override
public String handle(Object payload, Map headers) {
return new StringBuilder().append(testMessage)
.append(" ").toString();
}
}
}
4) I 구성을 업데이트하고
job:
demo:
testMessage: 'My ID is 789'
5 이눔 아 밀어)를 실행 새로 고침
curl -d{} http://localhost:8002/refresh
컨트롤러에 대한 나머지 호출에서 everyth 구성이 업데이트되었습니다.
["config 1 is: My ID is 789"]
그러나 통합 흐름에 나머지 통화에서
의 설정은 업데이트되지 않은 :[LOGGING DEMO] My ID is 123
구성을 새로 방해하는 빈의 일부 특정 행동이있다?
감사합니다.
멋진 설명에 감사드립니다. 게리. –
또한'job.demo' 키를 전용'@ ConfigurationProperties' 클래스에 넣으면'@ Value'에'@ RefreshScope'가 필요 없습니다. – spencergibb