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.DefaultResourceLoader;
028 import org.springframework.web.context.support.XmlWebApplicationContext;
029
030
040 public class PortalApplicationContext extends XmlWebApplicationContext {
041
042 @Override
043 protected void loadBeanDefinitions(
044 XmlBeanDefinitionReader xmlBeanDefinitionReader) {
045
046 try {
047 super.loadBeanDefinitions(xmlBeanDefinitionReader);
048 }
049 catch (Exception e) {
050 if (_log.isWarnEnabled()) {
051 _log.warn(e, e);
052 }
053 }
054
055 xmlBeanDefinitionReader.setResourceLoader(new DefaultResourceLoader());
056
057 if (PropsValues.SPRING_CONFIGS == null) {
058 return;
059 }
060
061 List<String> configLocations = ListUtil.fromArray(
062 PropsValues.SPRING_CONFIGS);
063
064 if (PropsValues.PERSISTENCE_PROVIDER.equalsIgnoreCase("jpa")) {
065 configLocations.remove("META-INF/hibernate-spring.xml");
066 }
067 else {
068 configLocations.remove("META-INF/jpa-spring.xml");
069 }
070
071 for (String configLocation : configLocations) {
072 try {
073 xmlBeanDefinitionReader.loadBeanDefinitions(configLocation);
074 }
075 catch (Exception e) {
076 Throwable cause = e.getCause();
077
078 if (cause instanceof FileNotFoundException) {
079 if (_log.isWarnEnabled()) {
080 _log.warn(cause.getMessage());
081 }
082 }
083 else {
084 _log.error(e, e);
085 }
086 }
087 }
088 }
089
090 private static Log _log = LogFactoryUtil.getLog(
091 PortalApplicationContext.class);
092
093 }