From 02b539c5f50b59d9f5605c21e42d53f0c8e23ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 30 Jun 2020 07:34:26 +0200 Subject: [PATCH] Leverage spring.ignore.xml flag to avoid XmlBeanDefinitionReader Closes gh-25338 --- .../ConfigurationClassBeanDefinitionReader.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java index 5f884f6fb5..1b3e6a9015 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java @@ -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; * @author Juergen Hoeller * @author Phillip Webb * @author Sam Brannen + * @author Sebastien Deleuze * @since 3.0 * @see ConfigurationClassParser */ @@ -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. + *

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 { // 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;