Spring 在不重新启动容器的情况下按需更改配置
SpringMVC+Java8+Tomcat8堆栈 我在yaml中维护我的配置,并使用Spring的Spring 在不重新启动容器的情况下按需更改配置,spring,spring-mvc,configuration,Spring,Spring Mvc,Configuration,SpringMVC+Java8+Tomcat8堆栈 我在yaml中维护我的配置,并使用Spring的PropertyPlaceHolderConfigure扁平化属性,并在bean中维护配置 今天,它有一个固有的问题,因为每当YML文件发生更改时,我都需要重新启动服务器 我相信有一些方法可以在不重启的情况下刷新bean,但我主要关心的是如何以故障安全的方式进行 假设有一个请求,当时配置是a,然后我们刷新配置,现在是B,但是如果任何后续的用户请求依赖于配置,那么它就会爆炸。将此配置添加到servl
PropertyPlaceHolderConfigure
扁平化属性,并在bean中维护配置
今天,它有一个固有的问题,因为每当YML文件发生更改时,我都需要重新启动服务器
我相信有一些方法可以在不重启的情况下刷新bean,但我主要关心的是如何以故障安全的方式进行
假设有一个请求,当时配置是a,然后我们刷新配置,现在是B,但是如果任何后续的用户请求依赖于配置,那么它就会爆炸。将此配置添加到servlet-context.xml以动态捕获属性更改:
<context:property-placeholder
location="file:${A_CONFIG_LOCATION}/configuration.properties" />
<beans:bean id="propertiesLoader"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="cacheSeconds" value="1" />
<beans:property name="basenames">
<beans:list>
<beans:value>file:${A_CONFIG_LOCATION}/configuration
</beans:value>
</beans:list>
</beans:property>
</beans:bean>
@Component
public class PropertiesReader {
private String value = "some_default_value";
@Autowired
MessageSource propertiesLoader;
public String getValue() {
value = propertiesLoader.getMessage("configuration.value", null, null);
return value;
}
}