1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.spring.context;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.util.PropsKeys;
25  import com.liferay.portal.util.PropsUtil;
26  
27  import java.io.FileNotFoundException;
28  
29  import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
30  import org.springframework.core.io.DefaultResourceLoader;
31  import org.springframework.web.context.support.XmlWebApplicationContext;
32  
33  /**
34   * <a href="PortalApplicationContext.java.html"><b><i>View Source</i></b></a>
35   *
36   * <p>
37   * This web application context will first load bean definitions in the
38   * contextConfigLocation parameter in web.xml. Then, the context will load bean
39   * definitions specified by the property "spring.configs" in portal.properties.
40   * </p>
41   *
42   * @author Brian Wing Shun Chan
43   * @author Alexander Chow
44   *
45   */
46  public class PortalApplicationContext extends XmlWebApplicationContext {
47  
48      protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
49          try {
50              super.loadBeanDefinitions(reader);
51          }
52          catch (Exception e) {
53              if (_log.isWarnEnabled()) {
54                  _log.warn(e, e);
55              }
56          }
57  
58          reader.setResourceLoader(new DefaultResourceLoader());
59  
60          String[] configLocations = PropsUtil.getArray(PropsKeys.SPRING_CONFIGS);
61  
62          if (configLocations == null) {
63              return;
64          }
65  
66          for (String configLocation : configLocations) {
67              try {
68                  reader.loadBeanDefinitions(configLocation);
69              }
70              catch (Exception e) {
71                  Throwable cause = e.getCause();
72  
73                  if (cause instanceof FileNotFoundException) {
74                      if (_log.isWarnEnabled()) {
75                          _log.warn(cause.getMessage());
76                      }
77                  }
78                  else {
79                      _log.error(e, e);
80                  }
81              }
82          }
83      }
84  
85      private static Log _log =
86           LogFactoryUtil.getLog(PortalApplicationContext.class);
87  
88  }