2017-04-13 170 views
2

我有這個Spring MVC應用程序,它使用PropertyPlaceholderConfigurer使用@Value註釋加載屬性。 我知道當上下文初始化時,所有屬性都在服務器啓動時加載。 Howevver,有沒有一種方法可以訪問更新的屬性而無需重新啓動TOMCAT? (可能使用Apache Commons PropertiesConfiguration)?彈簧重新加載屬性,無需重新啓動TOMCAT

有沒有一種方法可以配置Apache Commons PropertiesConfiguration以使用Spring PropertyPlaceholderconfigurer?

+0

你可以嘗試使用ReloadableResourceBundleMessageSource,細節在這個環節http://stackoverflow.com/questions/9035588/dynamically-load-files-on-classpath-using-reloadableresourcebundlemessagesource – ajup

回答

0
Add @RefreshScope annotation above the class which consumes the properties 
(ie has @Value annotation). Example goes as follows: 

    @RefreshScope 
    class PropertiesConsumer { 
    .... 
    @Value(..) 
    private consumerFoo; 
    .... 
    }