我有一個字符串,我自動裝配成一個bean。 String
的值通過屬性文件設置,並在運行時加載。我可以驗證那麼多。這裏是我的XML:如何在Spring中更新@Autowired String bean的值?
<context:property-placeholder location="classpath:my-app.properties" />
<bean id="loadedProp" class="java.lang.String">
<constructor-arg>
<value>${loaded-prop}</value>
</constructor-arg>
</bean>
而在我的申請,我在bean自動裝配:
@Component
public class Foo {
@Autowired
private String loadedProp;
}
一切工作的花花公子。我有多個在這個bean中自動裝配的組件。我試圖做的是,當應用程序正在運行時,將bean的值更新爲其他值,以便隨處自動裝入bean,它使用最新的值。是否有可能做到這一點,或者我每次需要重新啓動才需要更改值?
可能的重複http://stackoverflow.com/questions/2008175/apply-dynamic-properties-to-a-bean-at-runtime – beny23 2012-02-09 15:57:27
此鏈接可能會幫助你http://forum.springsource.org/archive /index.php/t-37557.html看看最後的帖子 – 2012-02-09 15:58:55
@ beny23嗯,謝謝。這在我的搜索中沒有出現。 – Pat 2012-02-09 16:00:29