独立应用程序的配置文件在运行时发生更改?
假设我有一个 Swing/Spring 独立应用程序。我想知道Spring是否检测到其配置文件的运行时更改,例如这个(假设该文件位于类路径上):
注释第二个bean并添加第一个bean,如下所示:
<beans>
<bean id="randonNumberGenerator" class="com.me.MyGenerator"/>
<!--
<bean id="randonNumberGenerator" class="com.someoneelse.ADifferentGenerator"/>
-->
</beans>
Spring会按预期在运行时更改实现吗?
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.ADifferentGenerator"/>
-->
</beans>
Will Spring change the implementation at runtime as expected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为 Spring 提供了一种即时重新加载配置的方法。可以通过重新实例化整个 ApplicationContext 来实现,但这意味着所有 bean 都会重新创建等,并且软件的内部状态可能会在此过程中飞出窗口。
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.
我认为您可以使用“AbstractRefreshableApplicationContext”来刷新上下文。
有关详细信息,您可以查看此处
I think you can use the "AbstractRefreshableApplicationContext" to refresh the context.
For details you can have a look here