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