2017-10-04 9 views
1

Spring MVCの+ Javaの8 + Tomcatの8スタック変更構成コンテナ

を再起動しなくても、私はYAMLで私の設定を維持し、SpringのPropertyPlaceholderConfigurerを使用し、Bean内の構成を維持する性質を平坦化しています。

今日、YMLファイルが変更されたときはいつでもサーバーを再起動する必要があるため、固有の問題があります。

私は、再起動せずにBeanをリフレッシュする方法があると信じていますが、私の主な関心事はフェールセーフなやり方です。

設定がAであったという要求があったと仮定して、今度は設定をBに変更しますが、その後のユーザー要求が設定に依存していた場合は、それは爆発します。このようにプロパティ値を

<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> 

をそして、あなたは読むことができます::

答えて

1

オンザフライでプロパティの変更をキャッチするサーブレット-のcontext.xmlにこの設定を追加

@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; 
    } 


} 
関連する問題