我有这个 Spring MVC 应用程序,它使用 PropertyPlaceholderConfigurer 来使用 @Value 注释加载属性。 我知道初始化上下文时所有属性都在服务器启动时加载。 Howevver,有没有一种方法可以访问更新的属性而无需重新启动 TOMCAT? (可能利用 Apache Commons PropertiesConfiguration)?
有没有一种方法可以将 Apache Commons PropertiesConfiguration 配置为与 Spring PropertyPlaceholderconfigurer 一起使用?
最佳答案
在使用属性的类上方添加@RefreshScope
注释(即具有@Value 注释)。示例如下:
@RefreshScope
class PropertiesConsumer {
....
@Value(..)
private consumerFoo;
....
}
关于Spring重新加载属性而不重启TOMCAT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43386080/