1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.spring.context;
16  
17  import com.liferay.portal.bean.BeanLocatorImpl;
18  import com.liferay.portal.kernel.bean.BeanLocator;
19  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
20  import com.liferay.portal.kernel.cache.ThreadLocalCacheManager;
21  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
22  import com.liferay.portal.util.InitUtil;
23  
24  import javax.servlet.ServletContextEvent;
25  
26  import org.springframework.beans.CachedIntrospectionResults;
27  import org.springframework.context.ApplicationContext;
28  import org.springframework.web.context.ContextLoader;
29  import org.springframework.web.context.ContextLoaderListener;
30  
31  /**
32   * <a href="PortalContextLoaderListener.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Michael Young
35   * @author Shuyang Zhou
36   */
37  public class PortalContextLoaderListener extends ContextLoaderListener {
38  
39      public void contextInitialized(ServletContextEvent event) {
40          InitUtil.init();
41  
42          super.contextInitialized(event);
43  
44          ApplicationContext applicationContext =
45              ContextLoader.getCurrentWebApplicationContext();
46  
47          ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
48  
49          BeanLocator beanLocator = new BeanLocatorImpl(
50              portalClassLoader, applicationContext);
51  
52          PortalBeanLocatorUtil.setBeanLocator(beanLocator);
53  
54          ClassLoader classLoader = portalClassLoader;
55  
56          while (classLoader != null) {
57              CachedIntrospectionResults.clearClassLoader(classLoader);
58  
59              classLoader = classLoader.getParent();
60          }
61      }
62  
63      public void contextDestroyed(ServletContextEvent event) {
64          super.contextDestroyed(event);
65  
66          ThreadLocalCacheManager.destroy();
67      }
68  
69  }