Spring重新加载属性而不重新启动TOMCAT

问题描述 投票:2回答:1

我有这个Spring MVC应用程序,它使用PropertyPlaceholderConfigurer来使用@Value注释加载属性。我知道在初始化上下文时,所有属性都在服务器启动时加载。但是,有没有办法可以访问更新的属性而无需重新启动TOMCAT? (也许使用Apache Commons PropertiesConfiguration)?

有没有办法配置Apache Commons PropertiesConfiguration以使用Spring PropertyPlaceholderconfigurer?

spring apache tomcat apache-commons dynamic-properties
1个回答
0
投票

在使用属性的类上面添加@RefreshScope注释(即具有@Value注释)。示例如下:

@RefreshScope
class PropertiesConsumer {
  ....
  @Value(..)
  private consumerFoo;
  ....
}
© www.soinside.com 2019 - 2024. All rights reserved.