我有一个疑问,我希望我的应用程序上下文每 2 分钟刷新一次。现在我正在我的应用程序中获取应用程序上下文..
public class App {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"Spring-Module.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloBean");
obj.printHello();
}
请告知如何每 2 分钟刷新一次应用程序上下文
最佳答案
引用此链接
http://hsenidians.blogspot.in/2007/07/reloading-spring-context-dynamically.html
http://techdive.in/spring/spring-refresh-application-context
试试这个
public class RefreshSpringContext {
public static void main(String args[]) {
SpringThread t = new SpringThread();
new Thread(t).start();
}
}
class SpringThread implements Runnable {
public SpringThread() {
}
public void run() {
try {
ApplicationContext context = = new ClassPathXmlApplicationContext("Spring-Module.xml");
((ConfigurableApplicationContext) context).refresh();
Thread.sleep(12000);
HelloWorld obj = (HelloWorld) context.getBean("helloBean");
obj.printHello();
} catch (Exception e) {
}
}
}
关于java - 每 2 分钟刷新一次应用程序上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11752481/