如何使用 Spring 重新加载属性? [英] How to reload properties with Spring?
问题描述
我在 Spring 3 中使用属性文件.当 Spring 初始化其上下文时,它会加载属性文件并将其放入所有带有 @Value 注释的 bean 中.
I'm using properties file with Spring 3. When Spring initializes its contex it loads the properties file and puts it in all beans with @Value annotation.
我希望有可能更新文件中的某些属性,并在服务器上公开一个 JMX,该 JMX 会将新属性重新加载到 Spring - 无需重新启动服务器并重新加载其上下文.
I want to have a possibility to update some properties in a file, and expose a JMX on the server that will reload the new properties to Spring - without restarting the server, and reloading its context.
我可以通过使用一些 Spring 方法来重新加载属性并将它们填充到所有 bean 中来实现这一点,还是我应该自己编写类似的东西?
Can I implement this by using some Spring method to reload properties and populate them to all beans, or should I write something like this by my own?
推荐答案
我建议用 PropertiesConfiguration 替换 java.util.Properties
"http://commons.apache.org/configuration" rel="noreferrer">Apache Commons Configuration 项目.它支持自动重新加载,通过检测文件何时更改,或通过 JMX 触发.
I would suggest replacing the java.util.Properties
with a PropertiesConfiguration
from the Apache Commons Configuration project. It supports automatic reloading, either by detecting when the file changes, or by triggering through JMX.
这篇关于如何使用 Spring 重新加载属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!