RESOLVED - issue SPR-6366: Cannot import bean definitions using classpath*: resource location

http://jira.springframework.org/browse/SPR-6366
This commit is contained in:
David Syer 2009-11-17 09:53:10 +00:00
parent 17887d24a1
commit 66939ded0f
4 changed files with 33 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.SystemPropertyUtils;
@ -172,9 +173,10 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
boolean absoluteLocation = false;
try {
absoluteLocation = ResourceUtils.toURI(location).isAbsolute();
absoluteLocation = ResourcePatternUtils.isUrl(location) || ResourceUtils.toURI(location).isAbsolute();
} catch (Exception ex) {
// cannot convert to an URI, considering the location relative
// unless it is the well-known Spring prefix classpath*:
}
// check the

View File

@ -82,6 +82,20 @@ public class XmlBeanDefinitionReaderTests extends TestCase {
testBeanDefinitions(registry);
}
public void testWithImport() {
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();;
Resource resource = new ClassPathResource("import.xml", getClass());
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
testBeanDefinitions(registry);
}
public void testWithWildcardImport() {
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();;
Resource resource = new ClassPathResource("importPattern.xml", getClass());
new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
testBeanDefinitions(registry);
}
public void testWithInputSource() {
try {
SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();;

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<import resource="classpath:/org/springframework/beans/factory/xml/test.xml"/>
</beans>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<import resource="classpath*:/org/springframework/beans/factory/xml/test.xml"/>
</beans>