Browse Source

Leverage spring.ignore.xml flag to avoid XmlBeanDefinitionReader

Closes gh-25338
pull/25349/head
Sébastien Deleuze 4 years ago
parent
commit
02b539c5f5
  1. 13
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java

13
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java

@ -44,6 +44,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -44,6 +44,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
import org.springframework.core.SpringProperties;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
@ -68,6 +69,7 @@ import org.springframework.util.StringUtils; @@ -68,6 +69,7 @@ import org.springframework.util.StringUtils;
* @author Juergen Hoeller
* @author Phillip Webb
* @author Sam Brannen
* @author Sebastien Deleuze
* @since 3.0
* @see ConfigurationClassParser
*/
@ -77,6 +79,14 @@ class ConfigurationClassBeanDefinitionReader { @@ -77,6 +79,14 @@ class ConfigurationClassBeanDefinitionReader {
private static final ScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver();
/**
* 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>The default is "false".
*/
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");
private final BeanDefinitionRegistry registry;
private final SourceExtractor sourceExtractor;
@ -349,6 +359,9 @@ class ConfigurationClassBeanDefinitionReader { @@ -349,6 +359,9 @@ class ConfigurationClassBeanDefinitionReader {
// When clearly asking for Groovy, that's what they'll get...
readerClass = GroovyBeanDefinitionReader.class;
}
else if (shouldIgnoreXml) {
throw new UnsupportedOperationException("XML support disabled");
}
else {
// Primarily ".xml" files but for any other extension as well
readerClass = XmlBeanDefinitionReader.class;

Loading…
Cancel
Save