From 42c3ac64ffcb47c30bdd156c12f0de0207873428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 10 Oct 2022 09:13:38 +0200 Subject: [PATCH] Remove spring.spel.ignore and spring.xml.ignore flags This commit also removes ResourcePropertiesPersister which was introduced in 5.3 specifically for spring.xml.ignore flag and which is expected to be used only internally by Spring Framework. DefaultPropertiesPersister should be used instead. Closes gh-29277 --- .../beans/PropertyEditorRegistrySupport.java | 13 +-- .../PropertiesBeanDefinitionReader.java | 10 +-- ...onfigurationClassBeanDefinitionReader.java | 11 --- .../event/EventListenerMethodProcessor.java | 16 +--- .../support/AbstractApplicationContext.java | 12 +-- ...ReloadableResourceBundleMessageSource.java | 11 ++- .../io/support/PropertiesLoaderSupport.java | 9 ++- .../io/support/PropertiesLoaderUtils.java | 20 +---- .../support/ResourcePropertiesPersister.java | 79 ------------------- .../util/DefaultPropertiesPersister.java | 10 ++- .../util/PropertiesPersister.java | 1 - .../jdbc/support/SQLErrorCodesFactory.java | 11 --- .../http/codec/support/BaseDefaultCodecs.java | 14 +--- ...lEncompassingFormHttpMessageConverter.java | 29 +++---- .../web/client/RestTemplate.java | 34 +++----- .../WebMvcConfigurationSupport.java | 41 ++++------ .../support/RouterFunctionMapping.java | 22 ++---- .../ExceptionHandlerExceptionResolver.java | 21 ++--- .../RequestMappingHandlerAdapter.java | 21 ++--- 19 files changed, 85 insertions(+), 300 deletions(-) delete mode 100644 spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertiesPersister.java diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index d62fc5d83b..2d39e2ef09 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -71,7 +71,6 @@ import org.springframework.beans.propertyeditors.URIEditor; import org.springframework.beans.propertyeditors.URLEditor; import org.springframework.beans.propertyeditors.UUIDEditor; import org.springframework.beans.propertyeditors.ZoneIdEditor; -import org.springframework.core.SpringProperties; import org.springframework.core.convert.ConversionService; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourceArrayPropertyEditor; @@ -93,14 +92,6 @@ import org.springframework.util.ClassUtils; */ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { - /** - * 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"); - - @Nullable private ConversionService conversionService; @@ -218,9 +209,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { this.defaultEditors.put(Currency.class, new CurrencyEditor()); this.defaultEditors.put(File.class, new FileEditor()); this.defaultEditors.put(InputStream.class, new InputStreamEditor()); - if (!shouldIgnoreXml) { - this.defaultEditors.put(InputSource.class, new InputSourceEditor()); - } + this.defaultEditors.put(InputSource.class, new InputSourceEditor()); this.defaultEditors.put(Locale.class, new LocaleEditor()); this.defaultEditors.put(Path.class, new PathEditor()); this.defaultEditors.put(Pattern.class, new PatternEditor()); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java index b12483a861..e85e080a3d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java @@ -35,8 +35,8 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; -import org.springframework.core.io.support.ResourcePropertiesPersister; import org.springframework.lang.Nullable; +import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; import org.springframework.util.StringUtils; @@ -148,7 +148,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader @Nullable private String defaultParentBean; - private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE; + private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE; /** @@ -187,12 +187,12 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader /** * Set the PropertiesPersister to use for parsing properties files. - * The default is ResourcePropertiesPersister. - * @see ResourcePropertiesPersister#INSTANCE + * The default is {@code DefaultPropertiesPersister}. + * @see DefaultPropertiesPersister#INSTANCE */ public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) { this.propertiesPersister = - (propertiesPersister != null ? propertiesPersister : ResourcePropertiesPersister.INSTANCE); + (propertiesPersister != null ? propertiesPersister : DefaultPropertiesPersister.INSTANCE); } /** 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 93f22542f6..66df6f8bcf 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 @@ -43,7 +43,6 @@ 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; @@ -78,13 +77,6 @@ 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; @@ -347,9 +339,6 @@ 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; diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java index 70c302fd02..16a1640fd1 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java @@ -40,7 +40,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.MethodIntrospector; -import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; @@ -65,14 +64,6 @@ import org.springframework.util.CollectionUtils; public class EventListenerMethodProcessor implements SmartInitializingSingleton, ApplicationContextAware, BeanFactoryPostProcessor { - /** - * Boolean flag controlled by a {@code spring.spel.ignore} system property that instructs Spring to - * ignore SpEL, i.e. to not initialize the SpEL infrastructure. - *

The default is "false". - */ - private static final boolean shouldIgnoreSpel = SpringProperties.getFlag("spring.spel.ignore"); - - protected final Log logger = LogFactory.getLog(getClass()); @Nullable @@ -91,12 +82,7 @@ public class EventListenerMethodProcessor public EventListenerMethodProcessor() { - if (shouldIgnoreSpel) { - this.evaluator = null; - } - else { - this.evaluator = new EventExpressionEvaluator(); - } + this.evaluator = new EventExpressionEvaluator(); } @Override diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 3c8b5c8aab..be2a0c3415 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -69,7 +69,6 @@ import org.springframework.context.weaving.LoadTimeWeaverAware; import org.springframework.context.weaving.LoadTimeWeaverAwareProcessor; import org.springframework.core.NativeDetector; import org.springframework.core.ResolvableType; -import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.convert.ConversionService; import org.springframework.core.env.ConfigurableEnvironment; @@ -159,13 +158,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader */ public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster"; - /** - * Boolean flag controlled by a {@code spring.spel.ignore} system property that instructs Spring to - * ignore SpEL, i.e. to not initialize the SpEL infrastructure. - *

The default is "false". - */ - private static final boolean shouldIgnoreSpel = SpringProperties.getFlag("spring.spel.ignore"); - static { // Eagerly load the ContextClosedEvent class to avoid weird classloader issues @@ -689,9 +681,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { // Tell the internal bean factory to use the context's class loader etc. beanFactory.setBeanClassLoader(getClassLoader()); - if (!shouldIgnoreSpel) { - beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader())); - } + beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader())); beanFactory.addPropertyEditorRegistrar(new ResourceEditorRegistrar(this, getEnvironment())); // Configure the bean factory with context callbacks. diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index 329cb743cf..8c809648a0 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -33,8 +33,8 @@ import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.ResourcePropertiesPersister; import org.springframework.lang.Nullable; +import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; import org.springframework.util.StringUtils; @@ -80,7 +80,6 @@ import org.springframework.util.StringUtils; * @see #setFileEncodings * @see #setPropertiesPersister * @see #setResourceLoader - * @see ResourcePropertiesPersister * @see org.springframework.core.io.DefaultResourceLoader * @see ResourceBundleMessageSource * @see java.util.ResourceBundle @@ -98,7 +97,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased private boolean concurrentRefresh = true; - private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE; + private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE; private ResourceLoader resourceLoader = new DefaultResourceLoader(); @@ -143,12 +142,12 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased /** * Set the PropertiesPersister to use for parsing properties files. - *

The default is ResourcePropertiesPersister. - * @see ResourcePropertiesPersister#INSTANCE + *

The default is {@code DefaultPropertiesPersister}. + * @see DefaultPropertiesPersister#INSTANCE */ public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) { this.propertiesPersister = - (propertiesPersister != null ? propertiesPersister : ResourcePropertiesPersister.INSTANCE); + (propertiesPersister != null ? propertiesPersister : DefaultPropertiesPersister.INSTANCE); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java index 0f33f9bfaf..a02c946033 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; +import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; /** @@ -56,7 +57,7 @@ public abstract class PropertiesLoaderSupport { @Nullable private String fileEncoding; - private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE; + private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE; /** @@ -130,12 +131,12 @@ public abstract class PropertiesLoaderSupport { /** * Set the PropertiesPersister to use for parsing properties files. - * The default is ResourcePropertiesPersister. - * @see ResourcePropertiesPersister#INSTANCE + * The default is {@code DefaultPropertiesPersister}. + * @see DefaultPropertiesPersister#INSTANCE */ public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) { this.propertiesPersister = - (propertiesPersister != null ? propertiesPersister : ResourcePropertiesPersister.INSTANCE); + (propertiesPersister != null ? propertiesPersister : DefaultPropertiesPersister.INSTANCE); } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java index a464f6b3de..85fe14691b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java @@ -24,11 +24,11 @@ import java.net.URLConnection; import java.util.Enumeration; import java.util.Properties; -import org.springframework.core.SpringProperties; import org.springframework.core.io.Resource; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; import org.springframework.util.ResourceUtils; @@ -49,13 +49,6 @@ public abstract class PropertiesLoaderUtils { private static final String XML_FILE_EXTENSION = ".xml"; - /** - * 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"); - /** * Load properties from the given EncodedResource, @@ -78,7 +71,7 @@ public abstract class PropertiesLoaderUtils { public static void fillProperties(Properties props, EncodedResource resource) throws IOException { - fillProperties(props, resource, ResourcePropertiesPersister.INSTANCE); + fillProperties(props, resource, DefaultPropertiesPersister.INSTANCE); } /** @@ -96,9 +89,6 @@ public abstract class PropertiesLoaderUtils { try { String filename = resource.getResource().getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } stream = resource.getInputStream(); persister.loadFromXml(props, stream); } @@ -144,9 +134,6 @@ public abstract class PropertiesLoaderUtils { try (InputStream is = resource.getInputStream()) { String filename = resource.getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } props.loadFromXML(is); } else { @@ -194,9 +181,6 @@ public abstract class PropertiesLoaderUtils { ResourceUtils.useCachesIfNecessary(con); try (InputStream is = con.getInputStream()) { if (resourceName.endsWith(XML_FILE_EXTENSION)) { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } props.loadFromXML(is); } else { diff --git a/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertiesPersister.java b/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertiesPersister.java deleted file mode 100644 index 1388c1c175..0000000000 --- a/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertiesPersister.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2002-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.core.io.support; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Properties; - -import org.springframework.core.SpringProperties; -import org.springframework.util.DefaultPropertiesPersister; - -/** - * Spring-aware subclass of the plain {@link DefaultPropertiesPersister}, - * adding a conditional check for disabled XML support through the shared - * "spring.xml.ignore" property. - * - *

This is the standard implementation used in Spring's resource support. - * - * @author Juergen Hoeller - * @author Sebastien Deleuze - * @since 5.3 - */ -public class ResourcePropertiesPersister extends DefaultPropertiesPersister { - - /** - * A convenient constant for a default {@code ResourcePropertiesPersister} instance, - * as used in Spring's common resource support. - * @since 5.3 - */ - public static final ResourcePropertiesPersister INSTANCE = new ResourcePropertiesPersister(); - - /** - * 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"); - - - @Override - public void loadFromXml(Properties props, InputStream is) throws IOException { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } - super.loadFromXml(props, is); - } - - @Override - public void storeToXml(Properties props, OutputStream os, String header) throws IOException { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } - super.storeToXml(props, os, header); - } - - @Override - public void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } - super.storeToXml(props, os, header, encoding); - } - -} diff --git a/spring-core/src/main/java/org/springframework/util/DefaultPropertiesPersister.java b/spring-core/src/main/java/org/springframework/util/DefaultPropertiesPersister.java index d0f3bc296f..cd885e3528 100644 --- a/spring-core/src/main/java/org/springframework/util/DefaultPropertiesPersister.java +++ b/spring-core/src/main/java/org/springframework/util/DefaultPropertiesPersister.java @@ -46,14 +46,22 @@ import java.util.Properties; * "defaultEncoding" and "fileEncodings" properties). * * @author Juergen Hoeller + * @author Sebastien Deleuze * @since 10.03.2004 * @see java.util.Properties * @see java.util.Properties#load * @see java.util.Properties#store - * @see org.springframework.core.io.support.ResourcePropertiesPersister */ public class DefaultPropertiesPersister implements PropertiesPersister { + /** + * A convenient constant for a default {@code DefaultPropertiesPersister} instance, + * as used in Spring's common resource support. + * @since 6.0 + */ + public static final DefaultPropertiesPersister INSTANCE = new DefaultPropertiesPersister(); + + @Override public void load(Properties props, InputStream is) throws IOException { props.load(is); diff --git a/spring-core/src/main/java/org/springframework/util/PropertiesPersister.java b/spring-core/src/main/java/org/springframework/util/PropertiesPersister.java index 6b6fcfd38a..0c8248dc74 100644 --- a/spring-core/src/main/java/org/springframework/util/PropertiesPersister.java +++ b/spring-core/src/main/java/org/springframework/util/PropertiesPersister.java @@ -35,7 +35,6 @@ import java.util.Properties; * @author Juergen Hoeller * @since 10.03.2004 * @see DefaultPropertiesPersister - * @see org.springframework.core.io.support.ResourcePropertiesPersister * @see java.util.Properties */ public interface PropertiesPersister { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java index 00869ece51..45452f0bcd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java @@ -28,7 +28,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.core.SpringProperties; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.lang.Nullable; @@ -67,13 +66,6 @@ public class SQLErrorCodesFactory { private static final Log logger = LogFactory.getLog(SQLErrorCodesFactory.class); - /** - * 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"); - /** * Keep track of a single instance so we can return it to classes that request it. */ @@ -109,9 +101,6 @@ public class SQLErrorCodesFactory { * @see #loadResource(String) */ protected SQLErrorCodesFactory() { - if (shouldIgnoreXml) { - throw new UnsupportedOperationException("XML support disabled"); - } Map errorCodes; diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java index d5d77ce726..31a6023d2e 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; -import org.springframework.core.SpringProperties; import org.springframework.core.codec.AbstractDataBufferDecoder; import org.springframework.core.codec.ByteArrayDecoder; import org.springframework.core.codec.ByteArrayEncoder; @@ -83,13 +82,6 @@ import org.springframework.util.ObjectUtils; */ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigurer.DefaultCodecConfig { - /** - * 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"); - static final boolean jackson2Present; private static final boolean jackson2SmilePresent; @@ -475,7 +467,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure ((AbstractJackson2Decoder) codec).setMaxInMemorySize(size); } } - if (jaxb2Present && !shouldIgnoreXml) { + if (jaxb2Present) { if (codec instanceof Jaxb2XmlDecoder) { ((Jaxb2XmlDecoder) codec).setMaxInMemorySize(size); } @@ -578,7 +570,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure addCodec(this.objectReaders, new DecoderHttpMessageReader<>(this.jackson2SmileDecoder != null ? (Jackson2SmileDecoder) this.jackson2SmileDecoder : new Jackson2SmileDecoder())); } - if (jaxb2Present && !shouldIgnoreXml) { + if (jaxb2Present) { addCodec(this.objectReaders, new DecoderHttpMessageReader<>(this.jaxb2Decoder != null ? (Jaxb2XmlDecoder) this.jaxb2Decoder : new Jaxb2XmlDecoder())); } @@ -702,7 +694,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure addCodec(writers, new EncoderHttpMessageWriter<>(this.jackson2SmileEncoder != null ? (Jackson2SmileEncoder) this.jackson2SmileEncoder : new Jackson2SmileEncoder())); } - if (jaxb2Present && !shouldIgnoreXml) { + if (jaxb2Present) { addCodec(writers, new EncoderHttpMessageWriter<>(this.jaxb2Encoder != null ? (Jaxb2XmlEncoder) this.jaxb2Encoder : new Jaxb2XmlEncoder())); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java index 1491e83108..975f6feb1f 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java @@ -16,7 +16,6 @@ package org.springframework.http.converter.support; -import org.springframework.core.SpringProperties; import org.springframework.http.converter.FormHttpMessageConverter; import org.springframework.http.converter.cbor.KotlinSerializationCborHttpMessageConverter; import org.springframework.http.converter.json.GsonHttpMessageConverter; @@ -41,13 +40,6 @@ import org.springframework.util.ClassUtils; */ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConverter { - /** - * 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 static final boolean jaxb2Present; private static final boolean jackson2Present; @@ -82,17 +74,16 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv public AllEncompassingFormHttpMessageConverter() { - if (!shouldIgnoreXml) { - try { - addPartConverter(new SourceHttpMessageConverter<>()); - } - catch (Error err) { - // Ignore when no TransformerFactory implementation is available - } - if (jaxb2Present && !jackson2XmlPresent) { - addPartConverter(new Jaxb2RootElementHttpMessageConverter()); - } + try { + addPartConverter(new SourceHttpMessageConverter<>()); + } + catch (Error err) { + // Ignore when no TransformerFactory implementation is available + } + + if (jaxb2Present && !jackson2XmlPresent) { + addPartConverter(new Jaxb2RootElementHttpMessageConverter()); } if (kotlinSerializationJsonPresent) { @@ -108,7 +99,7 @@ public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConv addPartConverter(new JsonbHttpMessageConverter()); } - if (jackson2XmlPresent && !shouldIgnoreXml) { + if (jackson2XmlPresent) { addPartConverter(new MappingJackson2XmlHttpMessageConverter()); } diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 1152f452d4..bf68ae3cf4 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -33,7 +33,6 @@ import io.micrometer.observation.ObservationConvention; import io.micrometer.observation.ObservationRegistry; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.core.SpringProperties; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -104,13 +103,6 @@ import org.springframework.web.util.UriTemplateHandler; */ public class RestTemplate extends InterceptingHttpAccessor implements RestOperations { - /** - * 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 static final boolean romePresent; private static final boolean jaxb2Present; @@ -174,14 +166,14 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat this.messageConverters.add(new ByteArrayHttpMessageConverter()); this.messageConverters.add(new StringHttpMessageConverter()); this.messageConverters.add(new ResourceHttpMessageConverter(false)); - if (!shouldIgnoreXml) { - try { - this.messageConverters.add(new SourceHttpMessageConverter<>()); - } - catch (Error err) { - // Ignore when no TransformerFactory implementation is available - } + + try { + this.messageConverters.add(new SourceHttpMessageConverter<>()); } + catch (Error err) { + // Ignore when no TransformerFactory implementation is available + } + this.messageConverters.add(new AllEncompassingFormHttpMessageConverter()); if (romePresent) { @@ -189,13 +181,11 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat this.messageConverters.add(new RssChannelHttpMessageConverter()); } - if (!shouldIgnoreXml) { - if (jackson2XmlPresent) { - this.messageConverters.add(new MappingJackson2XmlHttpMessageConverter()); - } - else if (jaxb2Present) { - this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); - } + if (jackson2XmlPresent) { + this.messageConverters.add(new MappingJackson2XmlHttpMessageConverter()); + } + else if (jaxb2Present) { + this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); } if (kotlinSerializationProtobufPresent) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 80647f21c8..9a3f5da09d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -33,7 +33,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.core.SpringProperties; import org.springframework.core.convert.converter.Converter; import org.springframework.format.Formatter; import org.springframework.format.FormatterRegistry; @@ -190,13 +189,6 @@ import org.springframework.web.util.pattern.PathPatternParser; */ public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware { - /** - * 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 static final boolean romePresent; private static final boolean jaxb2Present; @@ -460,7 +452,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv map.put("atom", MediaType.APPLICATION_ATOM_XML); map.put("rss", MediaType.APPLICATION_RSS_XML); } - if (!shouldIgnoreXml && (jaxb2Present || jackson2XmlPresent)) { + if (jaxb2Present || jackson2XmlPresent) { map.put("xml", MediaType.APPLICATION_XML); } if (jackson2Present || gsonPresent || jsonbPresent || kotlinSerializationJsonPresent) { @@ -888,14 +880,13 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv messageConverters.add(new StringHttpMessageConverter()); messageConverters.add(new ResourceHttpMessageConverter()); messageConverters.add(new ResourceRegionHttpMessageConverter()); - if (!shouldIgnoreXml) { - try { - messageConverters.add(new SourceHttpMessageConverter<>()); - } - catch (Throwable ex) { - // Ignore when no TransformerFactory implementation is available... - } + try { + messageConverters.add(new SourceHttpMessageConverter<>()); } + catch (Throwable ex) { + // Ignore when no TransformerFactory implementation is available... + } + messageConverters.add(new AllEncompassingFormHttpMessageConverter()); if (romePresent) { @@ -903,17 +894,15 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv messageConverters.add(new RssChannelHttpMessageConverter()); } - if (!shouldIgnoreXml) { - if (jackson2XmlPresent) { - Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.xml(); - if (this.applicationContext != null) { - builder.applicationContext(this.applicationContext); - } - messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.build())); - } - else if (jaxb2Present) { - messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); + if (jackson2XmlPresent) { + Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.xml(); + if (this.applicationContext != null) { + builder.applicationContext(this.applicationContext); } + messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.build())); + } + else if (jaxb2Present) { + messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); } if (kotlinSerializationCborPresent) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java index 5ffda8c829..5376aee637 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java @@ -25,7 +25,6 @@ import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; -import org.springframework.core.SpringProperties; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; @@ -57,14 +56,6 @@ import org.springframework.web.util.pattern.PathPatternParser; */ public class RouterFunctionMapping extends AbstractHandlerMapping implements InitializingBean { - /** - * 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"); - - @Nullable private RouterFunction routerFunction; @@ -198,14 +189,11 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini List> messageConverters = new ArrayList<>(4); messageConverters.add(new ByteArrayHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter()); - - if (!shouldIgnoreXml) { - try { - messageConverters.add(new SourceHttpMessageConverter<>()); - } - catch (Error err) { - // Ignore when no TransformerFactory implementation is available - } + try { + messageConverters.add(new SourceHttpMessageConverter<>()); + } + catch (Error err) { + // Ignore when no TransformerFactory implementation is available } messageConverters.add(new AllEncompassingFormHttpMessageConverter()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java index 4102e9ece2..1fb481f420 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java @@ -32,7 +32,6 @@ import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.core.SpringProperties; import org.springframework.http.HttpStatusCode; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; @@ -77,14 +76,6 @@ import org.springframework.web.servlet.support.RequestContextUtils; public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements ApplicationContextAware, InitializingBean { - /** - * 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"); - - @Nullable private List customArgumentResolvers; @@ -269,13 +260,11 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce } this.messageConverters.add(new ByteArrayHttpMessageConverter()); this.messageConverters.add(new StringHttpMessageConverter()); - if (!shouldIgnoreXml) { - try { - this.messageConverters.add(new SourceHttpMessageConverter<>()); - } - catch (Error err) { - // Ignore when no TransformerFactory implementation is available - } + try { + this.messageConverters.add(new SourceHttpMessageConverter<>()); + } + catch (Error err) { + // Ignore when no TransformerFactory implementation is available } this.messageConverters.add(new AllEncompassingFormHttpMessageConverter()); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index 77582713ac..d784cab7d1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -38,7 +38,6 @@ import org.springframework.core.KotlinDetector; import org.springframework.core.MethodIntrospector; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.log.LogFormatUtils; import org.springframework.core.task.AsyncTaskExecutor; @@ -117,13 +116,6 @@ import org.springframework.web.util.WebUtils; public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware, InitializingBean { - /** - * 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"); - /** * MethodFilter that matches {@link InitBinder @InitBinder} methods. */ @@ -576,14 +568,13 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter } this.messageConverters.add(new ByteArrayHttpMessageConverter()); this.messageConverters.add(new StringHttpMessageConverter()); - if (!shouldIgnoreXml) { - try { - this.messageConverters.add(new SourceHttpMessageConverter<>()); - } - catch (Error err) { - // Ignore when no TransformerFactory implementation is available - } + try { + this.messageConverters.add(new SourceHttpMessageConverter<>()); } + catch (Error err) { + // Ignore when no TransformerFactory implementation is available + } + this.messageConverters.add(new AllEncompassingFormHttpMessageConverter()); }