Skip to content

Commit

Permalink
Remove spring.spel.ignore and spring.xml.ignore flags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sdeleuze committed Oct 10, 2022
1 parent bca35dc commit 42c3ac6
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
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;
Expand All @@ -93,14 +92,6 @@
*/
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.
* <p>The default is "false".
*/
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");


@Nullable
private ConversionService conversionService;

Expand Down Expand Up @@ -218,9 +209,7 @@ private void createDefaultEditors() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
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;

Expand Down Expand Up @@ -148,7 +148,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
@Nullable
private String defaultParentBean;

private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE;
private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE;


/**
Expand Down Expand Up @@ -187,12 +187,12 @@ public String getDefaultParentBean() {

/**
* 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
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;
Expand Down Expand Up @@ -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.
* <p>The default is "false".
*/
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");

private final BeanDefinitionRegistry registry;

private final SourceExtractor sourceExtractor;
Expand Down Expand Up @@ -347,9 +339,6 @@ private void loadBeanDefinitionsFromImportedResources(
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;
Expand All @@ -65,14 +64,6 @@
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.
* <p>The default is "false".
*/
private static final boolean shouldIgnoreSpel = SpringProperties.getFlag("spring.spel.ignore");


protected final Log logger = LogFactory.getLog(getClass());

@Nullable
Expand All @@ -91,12 +82,7 @@ public class EventListenerMethodProcessor


public EventListenerMethodProcessor() {
if (shouldIgnoreSpel) {
this.evaluator = null;
}
else {
this.evaluator = new EventExpressionEvaluator();
}
this.evaluator = new EventExpressionEvaluator();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
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;
Expand Down Expand Up @@ -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.
* <p>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
Expand Down Expand Up @@ -689,9 +681,7 @@ protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
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;

Expand Down Expand Up @@ -80,7 +80,6 @@
* @see #setFileEncodings
* @see #setPropertiesPersister
* @see #setResourceLoader
* @see ResourcePropertiesPersister
* @see org.springframework.core.io.DefaultResourceLoader
* @see ResourceBundleMessageSource
* @see java.util.ResourceBundle
Expand All @@ -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();

Expand Down Expand Up @@ -143,12 +142,12 @@ public void setConcurrentRefresh(boolean concurrentRefresh) {

/**
* Set the PropertiesPersister to use for parsing properties files.
* <p>The default is ResourcePropertiesPersister.
* @see ResourcePropertiesPersister#INSTANCE
* <p>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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ public abstract class PropertiesLoaderSupport {
@Nullable
private String fileEncoding;

private PropertiesPersister propertiesPersister = ResourcePropertiesPersister.INSTANCE;
private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE;


/**
Expand Down Expand Up @@ -130,12 +131,12 @@ public void setFileEncoding(String encoding) {

/**
* 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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
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;

Expand All @@ -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.
* <p>The default is "false".
*/
private static final boolean shouldIgnoreXml = SpringProperties.getFlag("spring.xml.ignore");


/**
* Load properties from the given EncodedResource,
Expand All @@ -78,7 +71,7 @@ public static Properties loadProperties(EncodedResource resource) throws IOExcep
public static void fillProperties(Properties props, EncodedResource resource)
throws IOException {

fillProperties(props, resource, ResourcePropertiesPersister.INSTANCE);
fillProperties(props, resource, DefaultPropertiesPersister.INSTANCE);
}

/**
Expand All @@ -96,9 +89,6 @@ static void fillProperties(Properties props, EncodedResource resource, Propertie
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);
}
Expand Down Expand Up @@ -144,9 +134,6 @@ public static void fillProperties(Properties props, Resource resource) throws IO
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 {
Expand Down Expand Up @@ -194,9 +181,6 @@ public static Properties loadAllProperties(String resourceName, @Nullable ClassL
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 {
Expand Down

This file was deleted.

Loading

0 comments on commit 42c3ac6

Please sign in to comment.