|
|
@ -26,6 +26,7 @@ import groovy.lang.Closure;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
|
|
|
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
|
|
|
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
|
|
|
|
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.AbstractBeanDefinitionReader;
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
|
|
|
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;
|
|
|
@ -59,20 +60,14 @@ import org.springframework.util.StringUtils;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class BeanDefinitionLoader {
|
|
|
|
class BeanDefinitionLoader {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
// Static final field to facilitate code removal by Graal
|
|
|
|
* Boolean flag controlled by a {@code spring.xml.ignore} system property that
|
|
|
|
private static final boolean XML_ENABLED = !SpringProperties.getFlag("spring.xml.ignore");
|
|
|
|
* instructs Spring to ignore XML, i.e. to not initialize the XML-related
|
|
|
|
|
|
|
|
* infrastructure.
|
|
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* By default XML support is enabled.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static final boolean IS_XML_ENABLED = !SpringProperties.getFlag("spring.xml.ignore");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Object[] sources;
|
|
|
|
private final Object[] sources;
|
|
|
|
|
|
|
|
|
|
|
|
private final AnnotatedBeanDefinitionReader annotatedReader;
|
|
|
|
private final AnnotatedBeanDefinitionReader annotatedReader;
|
|
|
|
|
|
|
|
|
|
|
|
private final XmlBeanDefinitionReader xmlReader;
|
|
|
|
private final AbstractBeanDefinitionReader xmlReader;
|
|
|
|
|
|
|
|
|
|
|
|
private final BeanDefinitionReader groovyReader;
|
|
|
|
private final BeanDefinitionReader groovyReader;
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +86,7 @@ class BeanDefinitionLoader {
|
|
|
|
Assert.notEmpty(sources, "Sources must not be empty");
|
|
|
|
Assert.notEmpty(sources, "Sources must not be empty");
|
|
|
|
this.sources = sources;
|
|
|
|
this.sources = sources;
|
|
|
|
this.annotatedReader = new AnnotatedBeanDefinitionReader(registry);
|
|
|
|
this.annotatedReader = new AnnotatedBeanDefinitionReader(registry);
|
|
|
|
this.xmlReader = (IS_XML_ENABLED ? new XmlBeanDefinitionReader(registry) : null);
|
|
|
|
this.xmlReader = (XML_ENABLED ? new XmlBeanDefinitionReader(registry) : null);
|
|
|
|
this.groovyReader = (isGroovyPresent() ? new GroovyBeanDefinitionReader(registry) : null);
|
|
|
|
this.groovyReader = (isGroovyPresent() ? new GroovyBeanDefinitionReader(registry) : null);
|
|
|
|
this.scanner = new ClassPathBeanDefinitionScanner(registry);
|
|
|
|
this.scanner = new ClassPathBeanDefinitionScanner(registry);
|
|
|
|
this.scanner.addExcludeFilter(new ClassExcludeFilter(sources));
|
|
|
|
this.scanner.addExcludeFilter(new ClassExcludeFilter(sources));
|
|
|
@ -104,7 +99,7 @@ class BeanDefinitionLoader {
|
|
|
|
void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
|
|
|
|
void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
|
|
|
|
this.annotatedReader.setBeanNameGenerator(beanNameGenerator);
|
|
|
|
this.annotatedReader.setBeanNameGenerator(beanNameGenerator);
|
|
|
|
this.scanner.setBeanNameGenerator(beanNameGenerator);
|
|
|
|
this.scanner.setBeanNameGenerator(beanNameGenerator);
|
|
|
|
if (IS_XML_ENABLED) {
|
|
|
|
if (this.xmlReader != null) {
|
|
|
|
this.xmlReader.setBeanNameGenerator(beanNameGenerator);
|
|
|
|
this.xmlReader.setBeanNameGenerator(beanNameGenerator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -116,7 +111,7 @@ class BeanDefinitionLoader {
|
|
|
|
void setResourceLoader(ResourceLoader resourceLoader) {
|
|
|
|
void setResourceLoader(ResourceLoader resourceLoader) {
|
|
|
|
this.resourceLoader = resourceLoader;
|
|
|
|
this.resourceLoader = resourceLoader;
|
|
|
|
this.scanner.setResourceLoader(resourceLoader);
|
|
|
|
this.scanner.setResourceLoader(resourceLoader);
|
|
|
|
if (IS_XML_ENABLED) {
|
|
|
|
if (this.xmlReader != null) {
|
|
|
|
this.xmlReader.setResourceLoader(resourceLoader);
|
|
|
|
this.xmlReader.setResourceLoader(resourceLoader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -128,7 +123,7 @@ class BeanDefinitionLoader {
|
|
|
|
void setEnvironment(ConfigurableEnvironment environment) {
|
|
|
|
void setEnvironment(ConfigurableEnvironment environment) {
|
|
|
|
this.annotatedReader.setEnvironment(environment);
|
|
|
|
this.annotatedReader.setEnvironment(environment);
|
|
|
|
this.scanner.setEnvironment(environment);
|
|
|
|
this.scanner.setEnvironment(environment);
|
|
|
|
if (IS_XML_ENABLED) {
|
|
|
|
if (this.xmlReader != null) {
|
|
|
|
this.xmlReader.setEnvironment(environment);
|
|
|
|
this.xmlReader.setEnvironment(environment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -182,8 +177,8 @@ class BeanDefinitionLoader {
|
|
|
|
this.groovyReader.loadBeanDefinitions(source);
|
|
|
|
this.groovyReader.loadBeanDefinitions(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if (!IS_XML_ENABLED) {
|
|
|
|
if (this.xmlReader == null) {
|
|
|
|
throw new BeanDefinitionStoreException("Cannot load resources when XML support is disabled");
|
|
|
|
throw new BeanDefinitionStoreException("Cannot load XML bean definitions when XML support is disabled");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.xmlReader.loadBeanDefinitions(source);
|
|
|
|
this.xmlReader.loadBeanDefinitions(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|