1
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.ListUtil;
20 import com.liferay.portal.util.PropsValues;
21
22 import java.io.FileNotFoundException;
23
24 import java.util.List;
25
26 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
27 import org.springframework.core.io.DefaultResourceLoader;
28 import org.springframework.web.context.support.XmlWebApplicationContext;
29
30
42 public class PortalApplicationContext extends XmlWebApplicationContext {
43
44 protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) {
45 try {
46 super.loadBeanDefinitions(reader);
47 }
48 catch (Exception e) {
49 if (_log.isWarnEnabled()) {
50 _log.warn(e, e);
51 }
52 }
53
54 reader.setResourceLoader(new DefaultResourceLoader());
55
56 if (PropsValues.SPRING_CONFIGS == null) {
57 return;
58 }
59
60 List<String> configLocations = ListUtil.fromArray(
61 PropsValues.SPRING_CONFIGS);
62
63 if (PropsValues.PERSISTENCE_PROVIDER.equalsIgnoreCase("jpa")) {
64 configLocations.remove("META-INF/hibernate-spring.xml");
65 }
66 else {
67 configLocations.remove("META-INF/jpa-spring.xml");
68 }
69
70 for (String configLocation : configLocations) {
71 try {
72 reader.loadBeanDefinitions(configLocation);
73 }
74 catch (Exception e) {
75 Throwable cause = e.getCause();
76
77 if (cause instanceof FileNotFoundException) {
78 if (_log.isWarnEnabled()) {
79 _log.warn(cause.getMessage());
80 }
81 }
82 else {
83 _log.error(e, e);
84 }
85 }
86 }
87 }
88
89 private static Log _log = LogFactoryUtil.getLog(
90 PortalApplicationContext.class);
91
92 }