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

标签 spring apache tomcat apache-commons dynamic-properties

我有这个 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/

相关文章:

java - XmlSchemaCollection.read() 的 NoSuchMethodError

带有http的git克隆在gitlab中不起作用

apache - 基于接受语言的重定向

php - 是否有运行 php 和 servalet 程序的服务器?

java - 我的 Java 应用程序的日志在哪里?

java - 使用准备好的语句返回时间戳

java - spring-tx : Unable to locate Spring NamespaceHandler for XML schema namespace [http://www. springframework.org/schema/tx]

Spring Data - 如果参数为空值,则忽略参数

apache - 在 Curator 重试尝试时处理来自 ZooKeeper 的 EndOfStreamException?

tomcat - 使用基本的 tomcat 身份验证