Skip to content

Commit

Permalink
Don't use DataBinder to work out excludes
Browse files Browse the repository at this point in the history
Update `AutoConfigurationImportSelector` so that exclude properties
are loaded without invoking a `DataBinder`. This optimization helps
to improve application startup time.

See spring-projectsgh-7573
  • Loading branch information
philwebb committed Jan 24, 2017
1 parent 49fc727 commit f8ded6d
Showing 1 changed file with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.BeansException;
Expand All @@ -30,8 +32,6 @@
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
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;
Expand All @@ -47,6 +47,7 @@
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

/**
* {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration
Expand Down Expand Up @@ -200,12 +201,22 @@ protected Set<String> getExclusions(AnnotationMetadata metadata,

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(
this.environment, "spring.autoconfigure.");
Map<String, Object> properties = resolver.getSubProperties("exclude");
if (properties.isEmpty()) {
return Collections.emptyList();
}
List<String> excludes = new ArrayList<String>();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
if (name.isEmpty() || name.startsWith("[") && value != null) {
excludes.addAll(
StringUtils.commaDelimitedListToSet(String.valueOf(value)));
}
}
return excludes;
}
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(),
"spring.autoconfigure.");
Expand Down Expand Up @@ -317,21 +328,4 @@ public int getOrder() {
return Ordered.LOWEST_PRECEDENCE - 1;
}

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

}

}

0 comments on commit f8ded6d

Please sign in to comment.