1 16 17 package org.springframework.web.context.support; 18 19 import java.io.IOException ; 20 21 import org.springframework.beans.BeansException; 22 import org.springframework.beans.factory.support.DefaultListableBeanFactory; 23 import org.springframework.beans.factory.xml.ResourceEntityResolver; 24 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; 25 26 62 public class XmlWebApplicationContext extends AbstractRefreshableWebApplicationContext { 63 64 65 public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml"; 66 67 68 public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/"; 69 70 71 public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml"; 72 73 74 80 protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException { 81 XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); 83 84 beanDefinitionReader.setResourceLoader(this); 87 beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); 88 89 initBeanDefinitionReader(beanDefinitionReader); 92 loadBeanDefinitions(beanDefinitionReader); 93 } 94 95 104 protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) { 105 } 106 107 120 protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException { 121 String [] configLocations = getConfigLocations(); 122 if (configLocations != null) { 123 for (int i = 0; i < configLocations.length; i++) { 124 reader.loadBeanDefinitions(configLocations[i]); 125 } 126 } 127 } 128 129 134 protected String [] getDefaultConfigLocations() { 135 if (getNamespace() != null) { 136 return new String [] {DEFAULT_CONFIG_LOCATION_PREFIX + getNamespace() + DEFAULT_CONFIG_LOCATION_SUFFIX}; 137 } 138 else { 139 return new String [] {DEFAULT_CONFIG_LOCATION}; 140 } 141 } 142 143 } 144 | Popular Tags |