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.context.ApplicationContext;
26  import org.springframework.web.context.ContextLoader;
27  import org.springframework.web.context.ContextLoaderListener;
28  
29  /**
30   * <a href="PortalContextLoaderListener.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Michael Young
33   */
34  public class PortalContextLoaderListener extends ContextLoaderListener {
35  
36      public void contextInitialized(ServletContextEvent event) {
37          InitUtil.init();
38  
39          super.contextInitialized(event);
40  
41          ApplicationContext applicationContext =
42              ContextLoader.getCurrentWebApplicationContext();
43  
44          BeanLocator beanLocator = new BeanLocatorImpl(
45              PortalClassLoaderUtil.getClassLoader(), applicationContext);
46  
47          PortalBeanLocatorUtil.setBeanLocator(beanLocator);
48      }
49  
50  }