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.portlet.PortletBagPool;
023 import com.liferay.portal.kernel.util.InstancePool;
024 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
025 import com.liferay.portal.util.InitUtil;
026
027 import javax.servlet.ServletContextEvent;
028
029 import org.springframework.beans.CachedIntrospectionResults;
030 import org.springframework.context.ApplicationContext;
031 import org.springframework.web.context.ContextLoader;
032 import org.springframework.web.context.ContextLoaderListener;
033
034
038 public class PortalContextLoaderListener extends ContextLoaderListener {
039
040 public void contextInitialized(ServletContextEvent event) {
041 InitUtil.init();
042
043 super.contextInitialized(event);
044
045 ApplicationContext applicationContext =
046 ContextLoader.getCurrentWebApplicationContext();
047
048 ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
049
050 BeanLocator beanLocator = new BeanLocatorImpl(
051 portalClassLoader, applicationContext);
052
053 PortalBeanLocatorUtil.setBeanLocator(beanLocator);
054
055 ClassLoader classLoader = portalClassLoader;
056
057 while (classLoader != null) {
058 CachedIntrospectionResults.clearClassLoader(classLoader);
059
060 classLoader = classLoader.getParent();
061 }
062 }
063
064 public void contextDestroyed(ServletContextEvent event) {
065 super.contextDestroyed(event);
066
067 HotDeployUtil.reset();
068 InstancePool.reset();
069 PortletBagPool.reset();
070
071 ThreadLocalCacheManager.destroy();
072 }
073
074 }