001
014
015 package com.liferay.portal.spring.context;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.ListUtil;
020 import com.liferay.portal.util.PropsValues;
021
022 import java.io.FileNotFoundException;
023
024 import java.util.List;
025
026 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
027 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
028 import org.springframework.web.context.support.XmlWebApplicationContext;
029
030
041 public class PortalApplicationContext extends XmlWebApplicationContext {
042
043 @Override
044 protected void loadBeanDefinitions(
045 XmlBeanDefinitionReader xmlBeanDefinitionReader) {
046
047 try {
048 super.loadBeanDefinitions(xmlBeanDefinitionReader);
049 }
050 catch (Exception e) {
051 if (_log.isWarnEnabled()) {
052 _log.warn(e, e);
053 }
054 }
055
056 xmlBeanDefinitionReader.setResourceLoader(
057 new PathMatchingResourcePatternResolver());
058
059 if (PropsValues.SPRING_CONFIGS == null) {
060 return;
061 }
062
063 List<String> configLocations = ListUtil.fromArray(
064 PropsValues.SPRING_CONFIGS);
065
066 if (PropsValues.PERSISTENCE_PROVIDER.equalsIgnoreCase("jpa")) {
067 configLocations.remove("META-INF/hibernate-spring.xml");
068 }
069 else {
070 configLocations.remove("META-INF/jpa-spring.xml");
071 }
072
073 for (String configLocation : configLocations) {
074 try {
075 xmlBeanDefinitionReader.loadBeanDefinitions(configLocation);
076 }
077 catch (Exception e) {
078 Throwable cause = e.getCause();
079
080 if (cause instanceof FileNotFoundException) {
081 if (_log.isWarnEnabled()) {
082 _log.warn(cause.getMessage());
083 }
084 }
085 else {
086 _log.error(e, e);
087 }
088 }
089 }
090 }
091
092 private static Log _log = LogFactoryUtil.getLog(
093 PortalApplicationContext.class);
094
095 }