我正在使用来自 spring-cloud 的配置服务器。我希望刷新应用程序的配置而不必重新启动它。
这是我的场景:
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 Integration 的一个流程:
@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 的某些特殊行为会阻止刷新配置?
谢谢。