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