| SpringUtil.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * The contents of this file are subject to the terms of the Liferay Enterprise
5 * Subscription License ("License"). You may not use this file except in
6 * compliance with the License. You can obtain a copy of the License by
7 * contacting Liferay, Inc. See the License for the specific language governing
8 * permissions and limitations under the License, including but not limited to
9 * distribution rights of the Software.
10 *
11 *
12 *
13 */
14
15 package com.liferay.portal.spring.util;
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.kernel.util.PropsKeys;
22 import com.liferay.portal.spring.context.ArrayApplicationContext;
23 import com.liferay.portal.util.PropsUtil;
24
25 import org.springframework.context.support.AbstractApplicationContext;
26
27 /**
28 * <a href="SpringUtil.java.html"><b><i>View Source</i></b></a>
29 *
30 * <p>
31 * In most cases, SpringUtil.setContext() would have been called by
32 * com.liferay.portal.spring.context.PortalContextLoaderListener, configured in
33 * web.xml for the web application. However, there will be times in which
34 * SpringUtil will be called in a non-web application and, therefore, require
35 * manual instantiation of the application context.
36 * </p>
37 *
38 * @author Michael Young
39 */
40 public class SpringUtil {
41
42 public static void loadContext() {
43 AbstractApplicationContext applicationContext =
44 new ArrayApplicationContext(
45 PropsUtil.getArray(PropsKeys.SPRING_CONFIGS));
46
47 applicationContext.registerShutdownHook();
48
49 BeanLocator beanLocator = new BeanLocatorImpl(
50 PortalClassLoaderUtil.getClassLoader(), applicationContext);
51
52 PortalBeanLocatorUtil.setBeanLocator(beanLocator);
53 }
54
55 }