简体   繁体   English

如何在运行时更改xml中的Spring bean属性值?

[英]How to change spring bean property value in xml at runtime?

I have a springconfig.xml file and i used to get the bean property values from my.properties file. 我有一个springconfig.xml文件,我以前是从my.properties文件中获取bean属性值的。 property file values are changed dynamically. 属性文件的值是动态更改的。 but it will not set to the spring bean property. 但不会将其设置为spring bean属性。 it will change only after i restart my tomcat. 仅当我重新启动tomcat后,它才会更改。 Here is my part of xml code. 这是我的xml代码部分。

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
         <value>file:/SATHISH/apache.8.0.24/bin/my.properties</value>
     </property>
    </bean> 

<bean id="jmsEmailTemplateBean" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="authenticationConnectionFactory" />
    <property name="defaultDestination" ref="${queuename}" />
</bean>

if i change the my.properties value to "foo" it will work. 如果我将my.properties值更改为“ foo”,它将起作用。 again i change "foo" to "boo" at runtime it will not work. 我再次在运行时将“ foo”更改为“ boo”,它将无法正常工作。 It will not assign to ${queuename}. 它不会分配给$ {queuename}。

manually i changed my.properties value at runtime. 我在运行时手动更改了my.properties值。 it will not affect springconfig.xml 它不会影响springconfig.xml

It is possible to change xml values at runtime? 是否可以在运行时更改xml值? Thanks in advance 提前致谢

You'd need to watch the file programmatically in order to reload the changes or use this bean org.springframework.context.support.ReloadableResourceBundleMessageSource 您需要以编程方式查看文件,以便重新加载更改或使用此bean org.springframework.context.support.ReloadableResourceBundleMessageSource
to reload properties file. 重新加载属性文件。

尝试使用SpringBoot或IntelliJ Idea;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM