开发者

Configuration file changes at runtime for a standalone app?

Say I have a Swing/Spring standalone application. I am wondering whether Spring does detect runtime changes to its configuration file such as this one (assuming the file is on the classpath):

Commenting second bean and adding first bean as below:

<beans>
    <bean id="randonNumberGenerator"  class="com.me.MyGenerator"/>

    <!--
    <bean id="randonNumberGenerator"  class="com.someoneelse.开发者_如何学GoADifferentGenerator"/>
    -->
</beans>

Will Spring change the implementation at runtime as expected?


I don't think Spring provides a way to reload the configuration on-the-fly. It could be possible by re-instantiating the entire ApplicationContext, but that would mean that all beans are recreated etc., and internal state of the software would probably fly out the window in the process.


I think you can use the "AbstractRefreshableApplicationContext" to refresh the context.

AbstractRefreshableApplicationContext refreshableContext = new ClassPathXmlApplicationContext (  "applicationContextRefreshable.xml" );
 refreshableContext.refresh ( );

For details you can have a look here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜