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.context;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.PropsKeys;
20  import com.liferay.portal.util.PropsUtil;
21  
22  import java.io.FileNotFoundException;
23  
24  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
25  import org.springframework.core.io.DefaultResourceLoader;
26  import org.springframework.web.context.support.XmlWebApplicationContext;
27  
28  /**
29   * <a href="PortalApplicationContext.java.html"><b><i>View Source</i></b></a>
30   *
31   * <p>
32   * This web application context will first load bean definitions in the
33   * contextConfigLocation parameter in web.xml. Then, the context will load bean
34   * definitions specified by the property "spring.configs" in portal.properties.
35   * </p>
36   *
37   * @author Brian Wing Shun Chan
38   * @author Alexander Chow
39   */
40  public class PortalApplicationContext extends XmlWebApplicationContext {
41  
42      protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
43          try {
44              super.loadBeanDefinitions(reader);
45          }
46          catch (Exception e) {
47              if (_log.isWarnEnabled()) {
48                  _log.warn(e, e);
49              }
50          }
51  
52          reader.setResourceLoader(new DefaultResourceLoader());
53  
54          String[] configLocations = PropsUtil.getArray(PropsKeys.SPRING_CONFIGS);
55  
56          if (configLocations == null) {
57              return;
58          }
59  
60          for (String configLocation : configLocations) {
61              try {
62                  reader.loadBeanDefinitions(configLocation);
63              }
64              catch (Exception e) {
65                  Throwable cause = e.getCause();
66  
67                  if (cause instanceof FileNotFoundException) {
68                      if (_log.isWarnEnabled()) {
69                          _log.warn(cause.getMessage());
70                      }
71                  }
72                  else {
73                      _log.error(e, e);
74                  }
75              }
76          }
77      }
78  
79      private static Log _log = LogFactoryUtil.getLog(
80          PortalApplicationContext.class);
81  
82  }