Avoid unnecessary creation of default StandardEnvironment instances
Issue: SPR-10568
(cherry picked from commit 7e01578)
			
			
This commit is contained in:
		
							parent
							
								
									2ae61c503e
								
							
						
					
					
						commit
						a8adec7673
					
				| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -54,7 +54,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
 | 
			
		|||
 | 
			
		||||
	private ClassLoader beanClassLoader;
 | 
			
		||||
 | 
			
		||||
	private Environment environment = new StandardEnvironment();
 | 
			
		||||
	private Environment environment;
 | 
			
		||||
 | 
			
		||||
	private BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +90,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
 | 
			
		|||
 | 
			
		||||
		// Inherit Environment if possible
 | 
			
		||||
		if (this.registry instanceof EnvironmentCapable) {
 | 
			
		||||
			this.environment = ((EnvironmentCapable)this.registry).getEnvironment();
 | 
			
		||||
			this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			this.environment = new StandardEnvironment();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -78,9 +78,12 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new ResourceEditorRegistrar for the given ResourceLoader
 | 
			
		||||
	 * Create a new ResourceEditorRegistrar for the given {@link ResourceLoader}
 | 
			
		||||
	 * and {@link PropertyResolver}.
 | 
			
		||||
	 * @param resourceLoader the ResourceLoader (or ResourcePatternResolver)
 | 
			
		||||
	 * to create editors for (usually an ApplicationContext)
 | 
			
		||||
	 * @param propertyResolver the PropertyResolver (usually an Environment)
 | 
			
		||||
	 * @see org.springframework.core.env.Environment
 | 
			
		||||
	 * @see org.springframework.core.io.support.ResourcePatternResolver
 | 
			
		||||
	 * @see org.springframework.context.ApplicationContext
 | 
			
		||||
	 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +90,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a ClassPathScanningCandidateComponentProvider.
 | 
			
		||||
	 * Create a ClassPathScanningCandidateComponentProvider with a {@link StandardEnvironment}.
 | 
			
		||||
	 * @param useDefaultFilters whether to register the default filters for the
 | 
			
		||||
	 * {@link Component @Component}, {@link Repository @Repository},
 | 
			
		||||
	 * {@link Service @Service}, and {@link Controller @Controller}
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +101,15 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
 | 
			
		|||
		this(useDefaultFilters, new StandardEnvironment());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a ClassPathScanningCandidateComponentProvider with the given {@link Environment}.
 | 
			
		||||
	 * @param useDefaultFilters whether to register the default filters for the
 | 
			
		||||
	 * {@link Component @Component}, {@link Repository @Repository},
 | 
			
		||||
	 * {@link Service @Service}, and {@link Controller @Controller}
 | 
			
		||||
	 * stereotype annotations
 | 
			
		||||
	 * @param environment the Environment to use
 | 
			
		||||
	 * @see #registerDefaultFilters()
 | 
			
		||||
	 */
 | 
			
		||||
	public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) {
 | 
			
		||||
		if (useDefaultFilters) {
 | 
			
		||||
			registerDefaultFilters();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -437,7 +437,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
 | 
			
		|||
 | 
			
		||||
	public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
 | 
			
		||||
		return this.propertyResolver.getProperty(key, targetType, defaultValue);
 | 
			
		||||
	};
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public <T> Class<T> getPropertyAsClass(String key, Class<T> targetType) {
 | 
			
		||||
		return this.propertyResolver.getPropertyAsClass(key, targetType);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -16,8 +16,6 @@
 | 
			
		|||
 | 
			
		||||
package org.springframework.core.env;
 | 
			
		||||
 | 
			
		||||
import static java.lang.String.format;
 | 
			
		||||
 | 
			
		||||
import org.springframework.core.convert.ConversionException;
 | 
			
		||||
import org.springframework.util.ClassUtils;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -35,6 +33,7 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
 | 
			
		|||
 | 
			
		||||
	private final PropertySources propertySources;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new resolver against the given property sources.
 | 
			
		||||
	 * @param propertySources the set of {@link PropertySource} objects to use
 | 
			
		||||
| 
						 | 
				
			
			@ -43,106 +42,110 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
 | 
			
		|||
		this.propertySources = propertySources;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean containsProperty(String key) {
 | 
			
		||||
		for (PropertySource<?> propertySource : this.propertySources) {
 | 
			
		||||
			if (propertySource.containsProperty(key)) {
 | 
			
		||||
				return true;
 | 
			
		||||
		if (this.propertySources != null) {
 | 
			
		||||
			for (PropertySource<?> propertySource : this.propertySources) {
 | 
			
		||||
				if (propertySource.containsProperty(key)) {
 | 
			
		||||
					return true;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String getProperty(String key) {
 | 
			
		||||
		if (logger.isTraceEnabled()) {
 | 
			
		||||
			logger.trace(format("getProperty(\"%s\") (implicit targetType [String])", key));
 | 
			
		||||
		}
 | 
			
		||||
		return this.getProperty(key, String.class);
 | 
			
		||||
		return getProperty(key, String.class);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public <T> T getProperty(String key, Class<T> targetValueType) {
 | 
			
		||||
		boolean debugEnabled = logger.isDebugEnabled();
 | 
			
		||||
		if (logger.isTraceEnabled()) {
 | 
			
		||||
			logger.trace(format("getProperty(\"%s\", %s)", key, targetValueType.getSimpleName()));
 | 
			
		||||
			logger.trace(String.format("getProperty(\"%s\", %s)", key, targetValueType.getSimpleName()));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for (PropertySource<?> propertySource : this.propertySources) {
 | 
			
		||||
			if (debugEnabled) {
 | 
			
		||||
				logger.debug(format("Searching for key '%s' in [%s]", key, propertySource.getName()));
 | 
			
		||||
			}
 | 
			
		||||
			Object value;
 | 
			
		||||
			if ((value = propertySource.getProperty(key)) != null) {
 | 
			
		||||
				Class<?> valueType = value.getClass();
 | 
			
		||||
				if (String.class.equals(valueType)) {
 | 
			
		||||
					value = this.resolveNestedPlaceholders((String) value);
 | 
			
		||||
				}
 | 
			
		||||
		if (this.propertySources != null) {
 | 
			
		||||
			for (PropertySource<?> propertySource : this.propertySources) {
 | 
			
		||||
				if (debugEnabled) {
 | 
			
		||||
					logger.debug(
 | 
			
		||||
							format("Found key '%s' in [%s] with type [%s] and value '%s'",
 | 
			
		||||
									key, propertySource.getName(), valueType.getSimpleName(), value));
 | 
			
		||||
					logger.debug(String.format("Searching for key '%s' in [%s]", key, propertySource.getName()));
 | 
			
		||||
				}
 | 
			
		||||
				if (!this.conversionService.canConvert(valueType, targetValueType)) {
 | 
			
		||||
					throw new IllegalArgumentException(
 | 
			
		||||
							format("Cannot convert value [%s] from source type [%s] to target type [%s]",
 | 
			
		||||
									value, valueType.getSimpleName(), targetValueType.getSimpleName()));
 | 
			
		||||
				Object value;
 | 
			
		||||
				if ((value = propertySource.getProperty(key)) != null) {
 | 
			
		||||
					Class<?> valueType = value.getClass();
 | 
			
		||||
					if (String.class.equals(valueType)) {
 | 
			
		||||
						value = this.resolveNestedPlaceholders((String) value);
 | 
			
		||||
					}
 | 
			
		||||
					if (debugEnabled) {
 | 
			
		||||
						logger.debug(String.format("Found key '%s' in [%s] with type [%s] and value '%s'",
 | 
			
		||||
								key, propertySource.getName(), valueType.getSimpleName(), value));
 | 
			
		||||
					}
 | 
			
		||||
					if (!this.conversionService.canConvert(valueType, targetValueType)) {
 | 
			
		||||
						throw new IllegalArgumentException(String.format(
 | 
			
		||||
								"Cannot convert value [%s] from source type [%s] to target type [%s]",
 | 
			
		||||
								value, valueType.getSimpleName(), targetValueType.getSimpleName()));
 | 
			
		||||
					}
 | 
			
		||||
					return conversionService.convert(value, targetValueType);
 | 
			
		||||
				}
 | 
			
		||||
				return conversionService.convert(value, targetValueType);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (debugEnabled) {
 | 
			
		||||
			logger.debug(format("Could not find key '%s' in any property source. Returning [null]", key));
 | 
			
		||||
			logger.debug(String.format("Could not find key '%s' in any property source. Returning [null]", key));
 | 
			
		||||
		}
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public <T> Class<T> getPropertyAsClass(String key, Class<T> targetValueType) {
 | 
			
		||||
		boolean debugEnabled = logger.isDebugEnabled();
 | 
			
		||||
		if (logger.isTraceEnabled()) {
 | 
			
		||||
			logger.trace(format("getPropertyAsClass(\"%s\", %s)", key, targetValueType.getSimpleName()));
 | 
			
		||||
			logger.trace(String.format("getPropertyAsClass(\"%s\", %s)", key, targetValueType.getSimpleName()));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for (PropertySource<?> propertySource : this.propertySources) {
 | 
			
		||||
			if (debugEnabled) {
 | 
			
		||||
				logger.debug(format("Searching for key '%s' in [%s]", key, propertySource.getName()));
 | 
			
		||||
			}
 | 
			
		||||
			Object value;
 | 
			
		||||
			if ((value = propertySource.getProperty(key)) != null) {
 | 
			
		||||
		if (this.propertySources != null) {
 | 
			
		||||
			for (PropertySource<?> propertySource : this.propertySources) {
 | 
			
		||||
				if (debugEnabled) {
 | 
			
		||||
					logger.debug(
 | 
			
		||||
							format("Found key '%s' in [%s] with value '%s'", key, propertySource.getName(), value));
 | 
			
		||||
					logger.debug(String.format("Searching for key '%s' in [%s]", key, propertySource.getName()));
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				Class<?> clazz;
 | 
			
		||||
				if (value instanceof String) {
 | 
			
		||||
					try {
 | 
			
		||||
						clazz = ClassUtils.forName((String)value, null);
 | 
			
		||||
					} catch (Exception ex) {
 | 
			
		||||
						throw new ClassConversionException((String)value, targetValueType, ex);
 | 
			
		||||
				Object value = propertySource.getProperty(key);
 | 
			
		||||
				if (value != null) {
 | 
			
		||||
					if (debugEnabled) {
 | 
			
		||||
						logger.debug(String.format("Found key '%s' in [%s] with value '%s'", key, propertySource.getName(), value));
 | 
			
		||||
					}
 | 
			
		||||
					Class<?> clazz;
 | 
			
		||||
					if (value instanceof String) {
 | 
			
		||||
						try {
 | 
			
		||||
							clazz = ClassUtils.forName((String)value, null);
 | 
			
		||||
						}
 | 
			
		||||
						catch (Exception ex) {
 | 
			
		||||
							throw new ClassConversionException((String)value, targetValueType, ex);
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
					else if (value instanceof Class) {
 | 
			
		||||
						clazz = (Class<?>)value;
 | 
			
		||||
					}
 | 
			
		||||
					else {
 | 
			
		||||
						clazz = value.getClass();
 | 
			
		||||
					}
 | 
			
		||||
					if (!targetValueType.isAssignableFrom(clazz)) {
 | 
			
		||||
						throw new ClassConversionException(clazz, targetValueType);
 | 
			
		||||
					}
 | 
			
		||||
					@SuppressWarnings("unchecked")
 | 
			
		||||
					Class<T> targetClass = (Class<T>) clazz;
 | 
			
		||||
					return targetClass;
 | 
			
		||||
				}
 | 
			
		||||
				else if (value instanceof Class) {
 | 
			
		||||
					clazz = (Class<?>)value;
 | 
			
		||||
				} else {
 | 
			
		||||
					clazz = value.getClass();
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				if (!targetValueType.isAssignableFrom(clazz)) {
 | 
			
		||||
					throw new ClassConversionException(clazz, targetValueType);
 | 
			
		||||
				}
 | 
			
		||||
				@SuppressWarnings("unchecked")
 | 
			
		||||
				Class<T> targetClass = (Class<T>)clazz;
 | 
			
		||||
				return targetClass;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (debugEnabled) {
 | 
			
		||||
			logger.debug(format("Could not find key '%s' in any property source. Returning [null]", key));
 | 
			
		||||
			logger.debug(String.format("Could not find key '%s' in any property source. Returning [null]", key));
 | 
			
		||||
		}
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	@SuppressWarnings("serial")
 | 
			
		||||
	static class ClassConversionException extends ConversionException {
 | 
			
		||||
	private static class ClassConversionException extends ConversionException {
 | 
			
		||||
 | 
			
		||||
		public ClassConversionException(Class<?> actual, Class<?> expected) {
 | 
			
		||||
			super(String.format("Actual type %s is not assignable to expected type %s", actual.getName(), expected.getName()));
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -151,4 +154,5 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
 | 
			
		|||
			super(String.format("Could not find/load class %s during attempt to convert to %s", actual, expected.getName()), ex);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -19,12 +19,11 @@ package org.springframework.core.io;
 | 
			
		|||
import java.beans.PropertyEditorSupport;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
import org.springframework.core.env.StandardEnvironment;
 | 
			
		||||
import org.springframework.core.env.PropertyResolver;
 | 
			
		||||
import org.springframework.core.env.StandardEnvironment;
 | 
			
		||||
import org.springframework.util.Assert;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * {@link java.beans.PropertyEditor Editor} for {@link Resource}
 | 
			
		||||
 * descriptors, to automatically convert {@code String} locations
 | 
			
		||||
| 
						 | 
				
			
			@ -51,7 +50,7 @@ public class ResourceEditor extends PropertyEditorSupport {
 | 
			
		|||
 | 
			
		||||
	private final ResourceLoader resourceLoader;
 | 
			
		||||
 | 
			
		||||
	private final PropertyResolver propertyResolver;
 | 
			
		||||
	private PropertyResolver propertyResolver;
 | 
			
		||||
 | 
			
		||||
	private final boolean ignoreUnresolvablePlaceholders;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +60,7 @@ public class ResourceEditor extends PropertyEditorSupport {
 | 
			
		|||
	 * using a {@link DefaultResourceLoader} and {@link StandardEnvironment}.
 | 
			
		||||
	 */
 | 
			
		||||
	public ResourceEditor() {
 | 
			
		||||
		this(new DefaultResourceLoader(), new StandardEnvironment());
 | 
			
		||||
		this(new DefaultResourceLoader(), null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +72,21 @@ public class ResourceEditor extends PropertyEditorSupport {
 | 
			
		|||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public ResourceEditor(ResourceLoader resourceLoader) {
 | 
			
		||||
		this(resourceLoader, new StandardEnvironment(), true);
 | 
			
		||||
		this(resourceLoader, null, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new instance of the {@link ResourceEditor} class
 | 
			
		||||
	 * using the given {@link ResourceLoader}.
 | 
			
		||||
	 * @param resourceLoader the {@code ResourceLoader} to use
 | 
			
		||||
	 * @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
 | 
			
		||||
	 * if no corresponding property could be found
 | 
			
		||||
	 * @deprecated as of Spring 3.1 in favor of
 | 
			
		||||
	 * {@link #ResourceEditor(ResourceLoader, PropertyResolver, boolean)}
 | 
			
		||||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public ResourceEditor(ResourceLoader resourceLoader, boolean ignoreUnresolvablePlaceholders) {
 | 
			
		||||
		this(resourceLoader, null, ignoreUnresolvablePlaceholders);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -86,20 +99,6 @@ public class ResourceEditor extends PropertyEditorSupport {
 | 
			
		|||
		this(resourceLoader, propertyResolver, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new instance of the {@link ResourceEditor} class
 | 
			
		||||
	 * using the given {@link ResourceLoader}.
 | 
			
		||||
	 * @param resourceLoader the {@code ResourceLoader} to use
 | 
			
		||||
	 * @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
 | 
			
		||||
	 * if no corresponding property could be found
 | 
			
		||||
	 * @deprecated as of Spring 3.1 in favor of
 | 
			
		||||
	 * {@link #ResourceEditor(ResourceLoader, PropertyResolver, boolean)}
 | 
			
		||||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public ResourceEditor(ResourceLoader resourceLoader, boolean ignoreUnresolvablePlaceholders) {
 | 
			
		||||
		this(resourceLoader, new StandardEnvironment(), ignoreUnresolvablePlaceholders);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new instance of the {@link ResourceEditor} class
 | 
			
		||||
	 * using the given {@link ResourceLoader}.
 | 
			
		||||
| 
						 | 
				
			
			@ -110,7 +109,6 @@ public class ResourceEditor extends PropertyEditorSupport {
 | 
			
		|||
	 */
 | 
			
		||||
	public ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders) {
 | 
			
		||||
		Assert.notNull(resourceLoader, "ResourceLoader must not be null");
 | 
			
		||||
		Assert.notNull(propertyResolver, "PropertyResolver must not be null");
 | 
			
		||||
		this.resourceLoader = resourceLoader;
 | 
			
		||||
		this.propertyResolver = propertyResolver;
 | 
			
		||||
		this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
 | 
			
		||||
| 
						 | 
				
			
			@ -137,9 +135,11 @@ public class ResourceEditor extends PropertyEditorSupport {
 | 
			
		|||
	 * @see PropertyResolver#resolveRequiredPlaceholders
 | 
			
		||||
	 */
 | 
			
		||||
	protected String resolvePath(String path) {
 | 
			
		||||
		return this.ignoreUnresolvablePlaceholders ?
 | 
			
		||||
				this.propertyResolver.resolvePlaceholders(path) :
 | 
			
		||||
				this.propertyResolver.resolveRequiredPlaceholders(path);
 | 
			
		||||
		if (this.propertyResolver == null) {
 | 
			
		||||
			this.propertyResolver = new StandardEnvironment();
 | 
			
		||||
		}
 | 
			
		||||
		return (this.ignoreUnresolvablePlaceholders ? this.propertyResolver.resolvePlaceholders(path) :
 | 
			
		||||
				this.propertyResolver.resolveRequiredPlaceholders(path));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright 2002-2012 the original author or authors.
 | 
			
		||||
 * Copyright 2002-2013 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.
 | 
			
		||||
| 
						 | 
				
			
			@ -25,10 +25,12 @@ import java.util.List;
 | 
			
		|||
 | 
			
		||||
import org.apache.commons.logging.Log;
 | 
			
		||||
import org.apache.commons.logging.LogFactory;
 | 
			
		||||
import org.springframework.core.env.StandardEnvironment;
 | 
			
		||||
 | 
			
		||||
import org.springframework.core.env.Environment;
 | 
			
		||||
import org.springframework.core.env.PropertyResolver;
 | 
			
		||||
import org.springframework.core.env.StandardEnvironment;
 | 
			
		||||
import org.springframework.core.io.Resource;
 | 
			
		||||
import org.springframework.util.Assert;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Editor for {@link org.springframework.core.io.Resource} arrays, to
 | 
			
		||||
| 
						 | 
				
			
			@ -55,10 +57,10 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
 | 
			
		|||
 | 
			
		||||
	private static final Log logger = LogFactory.getLog(ResourceArrayPropertyEditor.class);
 | 
			
		||||
 | 
			
		||||
	private final PropertyResolver propertyResolver;
 | 
			
		||||
 | 
			
		||||
	private final ResourcePatternResolver resourcePatternResolver;
 | 
			
		||||
 | 
			
		||||
	private PropertyResolver propertyResolver;
 | 
			
		||||
 | 
			
		||||
	private final boolean ignoreUnresolvablePlaceholders;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -69,7 +71,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
 | 
			
		|||
	 * @see Environment
 | 
			
		||||
	 */
 | 
			
		||||
	public ResourceArrayPropertyEditor() {
 | 
			
		||||
		this(new PathMatchingResourcePatternResolver(), new StandardEnvironment(), true);
 | 
			
		||||
		this(new PathMatchingResourcePatternResolver(), null, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +82,20 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
 | 
			
		|||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver) {
 | 
			
		||||
		this(resourcePatternResolver, new StandardEnvironment(), true);
 | 
			
		||||
		this(resourcePatternResolver, null, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
 | 
			
		||||
	 * and a {@link StandardEnvironment}.
 | 
			
		||||
	 * @param resourcePatternResolver the ResourcePatternResolver to use
 | 
			
		||||
	 * @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
 | 
			
		||||
	 * if no corresponding system property could be found
 | 
			
		||||
	 * @deprecated as of 3.1 in favor of {@link #ResourceArrayPropertyEditor(ResourcePatternResolver, PropertyResolver, boolean)}
 | 
			
		||||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver, boolean ignoreUnresolvablePlaceholders) {
 | 
			
		||||
		this(resourcePatternResolver, null, ignoreUnresolvablePlaceholders);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -93,19 +108,6 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
 | 
			
		|||
		this(resourcePatternResolver, propertyResolver, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
 | 
			
		||||
	 * and a {@link StandardEnvironment}.
 | 
			
		||||
	 * @param resourcePatternResolver the ResourcePatternResolver to use
 | 
			
		||||
	 * @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
 | 
			
		||||
	 * if no corresponding system property could be found
 | 
			
		||||
	 * @deprecated as of 3.1 in favor of {@link #ResourceArrayPropertyEditor(ResourcePatternResolver, PropertyResolver, boolean)}
 | 
			
		||||
	 */
 | 
			
		||||
	@Deprecated
 | 
			
		||||
	public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver, boolean ignoreUnresolvablePlaceholders) {
 | 
			
		||||
		this(resourcePatternResolver, new StandardEnvironment(), ignoreUnresolvablePlaceholders);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
 | 
			
		||||
	 * and {@link PropertyResolver} (typically an {@link Environment}).
 | 
			
		||||
| 
						 | 
				
			
			@ -116,6 +118,8 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
 | 
			
		|||
	 */
 | 
			
		||||
	public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver,
 | 
			
		||||
			PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders) {
 | 
			
		||||
 | 
			
		||||
		Assert.notNull(resourcePatternResolver, "ResourcePatternResolver must not be null");
 | 
			
		||||
		this.resourcePatternResolver = resourcePatternResolver;
 | 
			
		||||
		this.propertyResolver = propertyResolver;
 | 
			
		||||
		this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
 | 
			
		||||
| 
						 | 
				
			
			@ -197,9 +201,11 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
 | 
			
		|||
	 * @see PropertyResolver#resolveRequiredPlaceholders(String)
 | 
			
		||||
	 */
 | 
			
		||||
	protected String resolvePath(String path) {
 | 
			
		||||
		return this.ignoreUnresolvablePlaceholders ?
 | 
			
		||||
				this.propertyResolver.resolvePlaceholders(path) :
 | 
			
		||||
				this.propertyResolver.resolveRequiredPlaceholders(path);
 | 
			
		||||
		if (this.propertyResolver == null) {
 | 
			
		||||
			this.propertyResolver = new StandardEnvironment();
 | 
			
		||||
		}
 | 
			
		||||
		return (this.ignoreUnresolvablePlaceholders ? this.propertyResolver.resolvePlaceholders(path) :
 | 
			
		||||
				this.propertyResolver.resolveRequiredPlaceholders(path));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue