我希望能够从我的 servlet 容器中运行的 Web 应用程序中获取所有 Spring 应用程序上下文的列表。这样我就可以重新初始化上下文,而无需重新启动或重新加载我的容器或 Web 应用程序。
这可能吗?如果是这样,如何?有没有办法通过 Servlet API 获取在 servlet 容器实例上运行的所有 servlet 上下文的列表?
最佳答案
[编辑:这并没有什么用,因为每个 web.xml 都必须有相同的监听器]
你可以有一个 ServletContextAttributeListener留意标准的插入 WebApplicationContext 属性,然后通知一些集中监视器?
未测试:
public class SpringWACListener implements ServletContextAttributeListener {
public void attributeAdded(ServletContextAttributeEvent scab) {
if (WebApplicationContext.
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.
equals(scab.getName()) {
myCentralisedMonitor.notify("added");
}
}
// same for others
}
关于java - 有没有办法获取在 JVM 中运行的所有 Spring 应用程序上下文的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/553546/