@ -16,9 +16,11 @@
package org.springframework.boot ;
package org.springframework.boot ;
import java.io.IOException ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.Set ;
import java.util.Set ;
import org.springframework.beans.factory.BeanDefinitionStoreException ;
import org.springframework.beans.factory.support.BeanDefinitionRegistry ;
import org.springframework.beans.factory.support.BeanDefinitionRegistry ;
import org.springframework.beans.factory.support.BeanNameGenerator ;
import org.springframework.beans.factory.support.BeanNameGenerator ;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader ;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader ;
@ -26,7 +28,6 @@ import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner ;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner ;
import org.springframework.core.annotation.AnnotationUtils ;
import org.springframework.core.annotation.AnnotationUtils ;
import org.springframework.core.env.ConfigurableEnvironment ;
import org.springframework.core.env.ConfigurableEnvironment ;
import org.springframework.core.io.DefaultResourceLoader ;
import org.springframework.core.io.Resource ;
import org.springframework.core.io.Resource ;
import org.springframework.core.io.ResourceLoader ;
import org.springframework.core.io.ResourceLoader ;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver ;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver ;
@ -49,7 +50,7 @@ import org.springframework.util.StringUtils;
* /
* /
class BeanDefinitionLoader {
class BeanDefinitionLoader {
private static final ResourceLoader DEFAULT_RESOURCE_LOADER = new DefaultResourceLoad er( ) ;
private static final ResourceLoader DEFAULT_RESOURCE_LOADER = new PathMatchingResourcePatternResolv er( ) ;
private Object [ ] sources ;
private Object [ ] sources ;
@ -153,22 +154,50 @@ class BeanDefinitionLoader {
}
}
private int load ( CharSequence source ) {
private int load ( CharSequence source ) {
String sourceString = xmlReader . getEnvironment ( ) . resolvePlaceholders ( source . toString ( ) ) ;
try {
try {
// Use class utils so that period separated nested class names work
// Use class utils so that period separated nested class names work
return load ( ClassUtils . forName ( source . to String( ) , null ) ) ;
return load ( ClassUtils . forName ( source String, null ) ) ;
}
}
catch ( ClassNotFoundException ex ) {
catch ( ClassNotFoundException ex ) {
// swallow exception and continue
// swallow exception and continue
}
}
Resource loadedResource = ( this . resourceLoader ! = null ? this . resourceLoader
ResourceLoader loader = this . resourceLoader ! = null ?
: DEFAULT_RESOURCE_LOADER ) . getResource ( source . toString ( ) ) ;
this . resourceLoader : DEFAULT_RESOURCE_LOADER ;
if ( loadedResource ! = null & & loadedResource . exists ( ) ) {
return load ( loadedResource ) ;
int loadCount = 0 ;
if ( loader instanceof ResourcePatternResolver ) {
// Resource pattern matching available.
try {
Resource [ ] resources = ( ( ResourcePatternResolver ) loader ) . getResources ( sourceString ) ;
for ( Resource resource : resources ) {
if ( resource . exists ( ) ) {
loadCount + = load ( resource ) ;
}
}
}
catch ( IOException ex ) {
throw new BeanDefinitionStoreException (
"Could not resolve bean definition resource pattern [" + sourceString + "]" , ex ) ;
}
}
}
Package packageResource = findPackage ( source ) ;
if ( ! ( loader instanceof ResourcePatternResolver ) ) {
if ( packageResource ! = null ) {
// Can only load single resources by absolute URL.
return load ( packageResource ) ;
Resource loadedResource = loader . getResource ( sourceString ) ;
if ( loadedResource ! = null & & loadedResource . exists ( ) ) {
return load ( loadedResource ) ;
}
}
if ( loadCount > 0 ) {
return loadCount ;
}
else {
// Attempt to treat the source as a package name, common to all PatternResolver types
Package packageResource = findPackage ( source ) ;
if ( packageResource ! = null ) {
return load ( packageResource ) ;
}
}
}
throw new IllegalArgumentException ( "Invalid source '" + source + "'" ) ;
throw new IllegalArgumentException ( "Invalid source '" + source + "'" ) ;
}
}