【发布时间】:2013-05-04 22:14:31
【问题描述】:
假设我们在 Spring 中有这样一个组件:
@Component
public class MyComponent {
@Value("${someProperty}")
private String text;
}
如果我们定义属性占位符:
<context:property-placeholder location="classpath:myProps.properties"/>
myPropos.properties 包含 someProperty 的值,该值将在上下文初始化时注入到 text 字段中。这非常简单易行。
但是假设我有一个服务可以让用户改变 someProperty 的值:
public void changeProp(String name, String newValue);
有没有机会我可以将 newValue 重新注入到文本字段中。我的意思是它应该很简单。基本上它与初始化后注入没有什么不同。我无法想象Spring不支持这个?我可以触发一些事件吗?
我基本上可以自己做这件事,但我想知道它可能已经存在了吗?如果没有,有谁知道 Spring 类实际上是在首先处理注射吗?如果解决方案不存在,我可能会重用那里的代码,我自己会执行此操作。
【问题讨论】:
标签: spring properties updates