Java 在运行时更新属性文件上的值
我的配置如下:Java 在运行时更新属性文件上的值,java,spring-mvc,spring-boot,properties-file,Java,Spring Mvc,Spring Boot,Properties File,我的配置如下: @Configuration public class PropertyConfiguration { @Bean @Profile("local") public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderC
@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
我试着用谷歌搜索,但没有一个答案能给我答案(
谢谢您的帮助。如果您要更改属性文件的值,它将不会影响运行时,因为所有配置都是在服务器启动时完成的,如果您不想重新部署代码库,您可以做一件事,更改属性文件值,然后重新启动服务器。您可以查看一下spring boot admin。尽管它充当监视服务器,但它使您能够更新属性和环境变量 附加一个屏幕截图展示了codecentric公司的概念证明
我知道……但我的要求是我不应该重新启动服务器或应用程序。:)没有其他选择