我有一个 Spring
上下文 xml 文件和一个由 PropertyPlaceholderConfigurer
机制创建的特定 bean。
我的问题是:当应用程序正在工作时,相关属性文件发生更改,并且我不想重新启动应用程序。我想重新加载相关的bean而不重新启动应用程序。
实现我的目标的最佳解决方案是什么?
最佳答案
你可以看看 github 上的 ReloadablePropertiesAnnotation
https://github.com/jamesemorgan/ReloadablePropertiesAnnotation
这应该通过注释你的属性来工作
@ReloadableProperty("dynamicProperty.myProperty")
private String myProperty;
您必须添加一些 spring 配置,请参阅 github 或此博客中的示例 http://www.morgan-design.com/2012/08/reloadable-application-properties-with.html
在底层,这是使用 Guava 的 EventBus 在创建 bean 后更新 bean 的属性。
关于java - Spring中的刷新属性占位符机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20262868/