Spring中从属资源更改时重新加载类 [英] Reload Class When Dependent Resource Changes in Spring

查看:334
本文介绍了Spring中从属资源更改时重新加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道当Eclipse依赖的资源文件(例如spring上下文文件)更新时,Eclipse如何重新加载在Tomcat中自动运行的类,从而您不必重新启动Tomcat吗?如何使一个类依赖于资源文件,以便在资源文件更改时Eclipse重新发布它? Eclipse将在更新其依赖资源文件时重新发布Spring类,但不会重新发布我的.

You know how Eclipse reloads classes automatically running in Tomcat when resource files they depend on such as spring context files are updated so that you don't have to re-start Tomcat? How do I make a class dependent on a resource file so that Eclipse re-publishes it when the resource file changes? Eclipse would re-publish Spring classes when their dependent resource files are updated, but would not re-publish mine.

推荐答案

您说要重新发布该类吗?您是说要更新应用程序上下文中Bean的内容吗?如果是这样,那么您可以执行以下操作:

You say that you want the class to be republished ? Do you mean that you want the contents of the bean in the application context to be updated ? If that's the case, then what you can do is the following :

1)编写文件系统监视器以监视资源的更改.有一个示例

1) Write a file system monitor to monitor the resource(s) for changes. There's an example on google code

2)每当文件/资源​​更改时,让该文件系统监视器触发自定义的Spring ApplicationEvent,并在必要时提供该事件的资源信息.即文件名,上次修改时间,上次修改时间等.

2) Have that file system monitor fire a custom Spring ApplicationEvent whenever the file / resource changes, providing that event the information for the resource, if necessary. ie the file name, the previous modified time, the last modified time, etc.

3)让要更新的bean实现ApplicationEventListener并在捕获文件系统监视器事件时重新加载资源.

3) Have the bean you want to be updated implement ApplicationEventListener and reload the resource when it catches your file system monitor event.

这篇关于Spring中从属资源更改时重新加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆