Spring mvc 为什么Spring上下文没有优雅地关闭?

Spring mvc 为什么Spring上下文没有优雅地关闭?,spring-mvc,memory-leaks,permgen,servlet-listeners,servletcontextlistener,Spring Mvc,Memory Leaks,Permgen,Servlet Listeners,Servletcontextlistener,在基于Spring framework 3.0.5的web应用程序的stop或undeploy/redeploy上,以下错误记录在Tomcat7的catalina.out: SEVERE: The web application [/nomination##1.0-qa] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4f43af8f]) and a val

在基于
Spring framework 3.0.5
的web应用程序的
stop
undeploy/redeploy
上,以下错误记录在
Tomcat7的catalina.out

SEVERE: The web application [/nomination##1.0-qa] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4f43af8f]) and a value of type [org.springframework.security.core.context.SecurityContextImpl] (value [org.springframework.security.core.context.SecurityContextImpl@ffffffff: Null authentication]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
我最初考虑在那里实现
ServletContextListener
close()
上下文。但是,在
web.xml
中设置了实现
ServletContextListener
的find
ContextLoaderListener

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
所以,我的问题是为什么
ContextLoaderListener.contextDestroyed()
不能干净地释放ThreadLocal

我们遇到了
PermGen
错误,在调查过程中发现了这一点。在一些地方有类似于以下的代码:

ApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(se.getSession().getServletContext());

MyBeanClass x = context.getBean(
            "myBean", MyBeanClass.class);
x.someMethod(); 
我想知道上面的代码片段是否正在阻止完全关闭?
任何提示都将不胜感激。

hotdeploy有许多问题需要注意:

1-注销数据库驱动程序

多任务应用程序中的2-关闭任务:您可能会将重启延迟置于开发模式下近1小时

3-Kill-context-of-spring:您已经完成了上面的操作,但请注意不要从XML导入XML

4-Kill存在于JVM内存中的缓存对象:创建小对象,您正在初始化吗 构造函数中的bean?将其更改为none构造函数,以保持在方法范围内杀死它们! 类中有多少方法调用bean?若许多方法调用bean不希望java kill对象从作用域中出来,jvm将保持它的性能,所以保持您的类较小

你的代码怎么样?您是否在循环外声明变量?使用后您是=空列表还是对象

5-您可以增加tomcat的开始时间和停止时间


也可以将rebel或springboot项目视为帮助程序。

将根应用程序上下文一分为二时,我开始出现此错误。我现在有一个用于引导的根上下文(具有相同的两个子servlet上下文),而不是具有两个子servlet上下文的单个根上下文,并且我稍后以编程方式创建一个子上下文。在本设计中,安全配置继续保留在根应用程序上下文中,但现在出现了泄漏警告。显然,在我的例子中,这与将根应用程序上下文一分为二有关。@Mihai Danila我只有一个应用程序上下文。您的安全上下文设置如何?您是否注销了驱动程序?@Override public void contextdestromed(ServletContextEvent arg0){Enumeration drivers=DriverManager.getDrivers();while(drivers.hasMoreElements()){Driver Driver=drivers.nextElement();try{DriverManager.deregisterDriver(Driver);}catch(SQLException e){}}@MihaiDanila我知道有点晚了,但是你能分享你的应用程序ctx吗?谢谢
ApplicationContext context = WebApplicationContextUtils
            .getWebApplicationContext(se.getSession().getServletContext());

MyBeanClass x = context.getBean(
            "myBean", MyBeanClass.class);
x.someMethod();