如何使用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,它会将新属性重新加载到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?
推荐答案
我建议用 java.util.Properties
> Apache Commons Configuration 项目中的PropertiesConfiguration 。它支持自动重新加载,通过检测文件何时更改,或通过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屋!