【发布时间】:2016-12-29 03:30:20
【问题描述】:
我正在使用 spring-cloud 中的 Config Server。我希望刷新应用程序的配置而不必重新启动它。
这是我的场景:
1) application.yml 中的单个配置,存储在 git
job:
demo:
testMessage: 'My ID is 123'
2) 客户端中的 Actuator 和控制器中的注解 @RefreshScope。
@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) 使用 Spring 集成的一个流程:
@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) 我更新配置并推送到 git
job:
demo:
testMessage: 'My ID is 789'
5) 运行刷新
curl -d{} http://localhost:8002/refresh
在对控制器的其余调用中,一切正常,配置已更新。
["config 1 is: My ID is 789"]
但是在其余的集成流程调用中,配置没有更新:
[LOGGING DEMO] My ID is 123
bean 的某些特定行为会阻止刷新配置?
谢谢。
【问题讨论】:
标签: spring spring-integration spring-cloud spring-cloud-config