В stop или undeploy/redeploy веб-приложения на основе Spring framework 3.0.5 следующая ошибка регистрируется в Tomcat7 catalina.out:
SEVERE: The web application [/nomination##1.0-qa] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [[email protected]]) and a value of type [org.springframework.security.core.context.SecurityContextImpl] (value [[email protected]ffffff: 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() контекста. Тем не менее, найденный ContextLoaderListener, который реализует ServletContextListener, устанавливается таким образом в web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Из Javadocs:
**contextDestroyed**
public void contextDestroyed(ServletContextEvent event)
Close the root web application context.
Specified by:
contextDestroyed in interface ServletContextListener
Итак, мой вопрос в том, почему ThreadLocal не очищается с помощью ContextLoaderListener.contextDestroyed()?
Мы сталкиваемся с ошибками PermGen, и при исследовании обнаруживаем это. В нескольких местах есть код, похожий на следующий:
ApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(se.getSession().getServletContext());
MyBeanClass x = context.getBean(
"myBean", MyBeanClass.class);
x.someMethod();
Интересно, останавливается ли вышеприведенный фрагмент на чистое завершение? Любые указатели будут очень благодарны.