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.util.PortalClassLoaderUtil;
21  import com.liferay.portal.util.InitUtil;
22  
23  import javax.servlet.ServletContextEvent;
24  
25  import org.springframework.beans.CachedIntrospectionResults;
26  import org.springframework.context.ApplicationContext;
27  import org.springframework.web.context.ContextLoader;
28  import org.springframework.web.context.ContextLoaderListener;
29  
30  /**
31   * <a href="PortalContextLoaderListener.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Michael Young
34   * @author Shuyang Zhou
35   */
36  public class PortalContextLoaderListener extends ContextLoaderListener {
37  
38      public void contextInitialized(ServletContextEvent event) {
39          InitUtil.init();
40  
41          super.contextInitialized(event);
42  
43          ApplicationContext applicationContext =
44              ContextLoader.getCurrentWebApplicationContext();
45  
46          ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();
47  
48          BeanLocator beanLocator = new BeanLocatorImpl(
49              portalClassLoader, applicationContext);
50  
51          PortalBeanLocatorUtil.setBeanLocator(beanLocator);
52  
53          ClassLoader classLoader = portalClassLoader;
54  
55          while (classLoader != null) {
56              CachedIntrospectionResults.clearClassLoader(classLoader);
57  
58              classLoader = classLoader.getParent();
59          }
60      }
61  
62  }