Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 在不重新启动容器的情况下按需更改配置_Spring_Spring Mvc_Configuration - Fatal编程技术网

Spring 在不重新启动容器的情况下按需更改配置

Spring 在不重新启动容器的情况下按需更改配置,spring,spring-mvc,configuration,Spring,Spring Mvc,Configuration,SpringMVC+Java8+Tomcat8堆栈 我在yaml中维护我的配置,并使用Spring的PropertyPlaceHolderConfigure扁平化属性,并在bean中维护配置 今天,它有一个固有的问题,因为每当YML文件发生更改时,我都需要重新启动服务器 我相信有一些方法可以在不重启的情况下刷新bean,但我主要关心的是如何以故障安全的方式进行 假设有一个请求,当时配置是a,然后我们刷新配置,现在是B,但是如果任何后续的用户请求依赖于配置,那么它就会爆炸。将此配置添加到servl

SpringMVC+Java8+Tomcat8堆栈

我在yaml中维护我的配置,并使用Spring的
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;
    }


}