Use RelaxedDataBinder for excludes
Update `EnableAutoConfigurationImportSelector` to directly use the RelaxedDataBinder when obtaining excludes. This removes the need for the additional getProperties method on RelaxedPropertyResolver. See gh-4352
This commit is contained in:
@@ -30,6 +30,8 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
|
||||
import org.springframework.boot.bind.PropertySourcesPropertyValues;
|
||||
import org.springframework.boot.bind.RelaxedDataBinder;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
@@ -37,6 +39,7 @@ import org.springframework.context.annotation.DeferredImportSelector;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
@@ -151,14 +154,18 @@ public class EnableAutoConfigurationImportSelector implements DeferredImportSele
|
||||
}
|
||||
|
||||
private List<String> getExcludeAutoConfigurationsProperty() {
|
||||
if (getEnvironment() instanceof ConfigurableEnvironment) {
|
||||
Excludes excludes = new Excludes();
|
||||
RelaxedDataBinder binder = new RelaxedDataBinder(excludes,
|
||||
"spring.autoconfigure.");
|
||||
binder.bind(new PropertySourcesPropertyValues(
|
||||
((ConfigurableEnvironment) getEnvironment()).getPropertySources()));
|
||||
return excludes.getExclude();
|
||||
}
|
||||
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(),
|
||||
"spring.autoconfigure.");
|
||||
Collection<Object> raw = resolver.getProperties("exclude");
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (Object r : raw) {
|
||||
values.add(r.toString());
|
||||
}
|
||||
return values;
|
||||
String[] exclude = resolver.getProperty("exclude", String[].class);
|
||||
return (Arrays.asList(exclude == null ? new String[0] : exclude));
|
||||
}
|
||||
|
||||
private List<String> sort(List<String> configurations) throws IOException {
|
||||
@@ -221,4 +228,21 @@ public class EnableAutoConfigurationImportSelector implements DeferredImportSele
|
||||
return this.resourceLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bindable object used to get excludes.
|
||||
*/
|
||||
static class Excludes {
|
||||
|
||||
private List<String> exclude = new ArrayList<String>();
|
||||
|
||||
public List<String> getExclude() {
|
||||
return this.exclude;
|
||||
}
|
||||
|
||||
public void setExclude(List<String> excludes) {
|
||||
this.exclude = excludes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user