001
014
015 package com.liferay.portal.spring.context;
016
017 import com.liferay.portal.bean.BeanLocatorImpl;
018 import com.liferay.portal.kernel.bean.BeanLocator;
019 import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
020 import com.liferay.portal.kernel.cache.ThreadLocalCacheManager;
021 import com.liferay.portal.kernel.deploy.hot.HotDeployUtil;
022 import com.liferay.portal.kernel.log.Log;
023 import com.liferay.portal.kernel.log.LogFactoryUtil;
024 import com.liferay.portal.kernel.portlet.PortletBagPool;
025 import com.liferay.portal.kernel.util.ClearThreadLocalUtil;
026 import com.liferay.portal.kernel.util.ClearTimerThreadUtil;
027 import com.liferay.portal.kernel.util.InstancePool;
028 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
029 import com.liferay.portal.util.InitUtil;
030
031 import javax.servlet.ServletContextEvent;
032
033 import org.springframework.beans.CachedIntrospectionResults;
034 import org.springframework.context.ApplicationContext;
035 import org.springframework.web.context.ContextLoader;
036 import org.springframework.web.context.ContextLoaderListener;
037
038
042 public class PortalContextLoaderListener extends ContextLoaderListener {
043
044 public void contextInitialized(ServletContextEvent event) {
045 InitUtil.init();
046
047 super.contextInitialized(event);
048
049 ApplicationContext applicationContext =
050 ContextLoader.getCurrentWebApplicationContext();
051
052 ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
053
054 BeanLocator beanLocator = new BeanLocatorImpl(
055 portalClassLoader, applicationContext);
056
057 PortalBeanLocatorUtil.setBeanLocator(beanLocator);
058
059 ClassLoader classLoader = portalClassLoader;
060
061 while (classLoader != null) {
062 CachedIntrospectionResults.clearClassLoader(classLoader);
063
064 classLoader = classLoader.getParent();
065 }
066 }
067
068 public void contextDestroyed(ServletContextEvent event) {
069 super.contextDestroyed(event);
070
071 HotDeployUtil.reset();
072 InstancePool.reset();
073 PortletBagPool.reset();
074
075 ThreadLocalCacheManager.destroy();
076
077 try {
078 ClearThreadLocalUtil.clearThreadLocal();
079 }
080 catch (Exception e) {
081 _log.error(e, e);
082 }
083
084 try {
085 ClearTimerThreadUtil.clearTimerThread();
086 }
087 catch(Exception e) {
088 _log.error(e, e);
089 }
090 }
091
092 private Log _log = LogFactoryUtil.getLog(PortalContextLoaderListener.class);
093
094 }