【问题标题】:Spring reload properties without restarting TOMCAT在不重启 TOMCAT 的情况下 Spring 重新加载属性
【发布时间】:2017-09-09 05:03:36
【问题描述】:

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

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

【问题讨论】:

标签: spring apache tomcat apache-commons dynamic-properties


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2014-03-11
    • 1970-01-01
    • 2012-01-28
    • 2010-09-15
    • 1970-01-01
    相关资源
    最近更新 更多