我的网络应用程序有一个方法test
每两分钟由 cronjob 调用一次,我希望能够在solution a
and solution b
带有一些功能标志,而无需每次都部署它。
@Scheduled(fixedRateService = "120000")
public void test(){
if(conditionA()) {
// do solution A
} else {
// do solution B
}
}
我正在考虑使用 cookie 来实现此目的,但它仅适用于我打开的会话,并且其他解决方案仍然可以由其他会话调用。
有什么方法可以强制在生产中仅运行一个解决方案并动态交换它们,而无需每次都释放它们?
Update:Jonathan Johx 的答案是正确的,我在这里添加一些说明
要更新您首先需要的属性的值POST
你的键/值x-www-form-urlencoded
格式化为\actuator\env
,然后通过将空有效负载发送到\actuator\refresh
你可能会使用@RefreshScope https://cloud.spring.io/spring-cloud-static/spring-cloud.html#_refresh_scope刷新属性的注释:
1.- Add @RefreshScope
上课时
@RefreshScope
@Component
public class Test {
@Value("${conditional.istrue}")
private boolean conditional;
@Scheduled(fixedRateService = "120000")
public void test(){
if(conditional) {
// do solution A
} else {
// do solution B
}
}
}
2.-添加标志属性并允许暴露端点/refresh
以便刷新新的属性。
应用程序属性
conditional.istrue=true
management.endpoints.web.exposure.include=*
3.-一旦 application.properties 被修改,例如:
conditional.istrue=false
然后你可以refresh
注入的配置执行:
curl localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"
参考
- https://spring.io/guides/gs/centralized-configuration/ https://spring.io/guides/gs/centralized-configuration/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)