2017-02-09 45 views
0

文件我已經配置如下:更新值上運行

@Configuration 
public class PropertyConfiguration { 

    @Bean 
    @Profile("local") 
    public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { 
     PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); 
     configurer.setLocation(new FileSystemResource("path/to/resources/app-local.properties")); 
     configurer.setIgnoreUnresolvablePlaceholders(true); 
     return configurer; 
    } 
} 

app-local.properties文件包含值:

cache.time.milliseconds=1000 

所以,我訪問值:

@Value("${cache.time.milliseconds}") 
    private long cachingTime; 

我收到了正確的值。

System.out.println(cachingTime); 

現在,我要更新cachingTime其他一些價值,服務其更新值。例如,從1000到99.

有什麼辦法可以在運行時更新這個屬性值?

或者除了重新啓動應用程序或服務器之外,還有其他更新此值的方式嗎?

我正在使用Spring Boot 1.4.3.RELEASE。

我試圖谷歌它,但沒有答案給了我解決方案。 :(

感謝您的任何幫助。

回答

0

如果因爲所有的配置完成後,你會改變屬性的文件也不會在運行時實現的價值,同時服務器開始,如果你不想重新部署代碼庫你可以做一件事,改變屬性文件的值,然後重新啓動服務器。

+0

我知道......但我的要求是我不應該重啓服務器或應用程序。 :) –

+0

沒有其他選擇 –