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