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
This commit is contained in:
Sébastien Deleuze
2022-10-10 09:13:38 +02:00
parent bca35dc0a2
commit 42c3ac64ff
19 changed files with 85 additions and 300 deletions

View File

@@ -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);
}

View File

@@ -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.
* <p>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 {

View File

@@ -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.
*
* <p>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.
* <p>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);
}
}

View File

@@ -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);

View File

@@ -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 {