From f8ded6de633aee8cba00722d98f912eaf1bde22d Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 21 Jan 2017 07:38:52 -0800 Subject: [PATCH] Don't use DataBinder to work out excludes Update `AutoConfigurationImportSelector` so that exclude properties are loaded without invoking a `DataBinder`. This optimization helps to improve application startup time. See gh-7573 --- .../AutoConfigurationImportSelector.java | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index c4ba455780..0df9a1c36d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -19,8 +19,10 @@ package org.springframework.boot.autoconfigure; 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; @@ -30,8 +32,6 @@ import org.springframework.beans.factory.BeanFactory; 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; @@ -47,6 +47,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; 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 @@ -200,12 +201,22 @@ public class AutoConfigurationImportSelector private List 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 properties = resolver.getSubProperties("exclude"); + if (properties.isEmpty()) { + return Collections.emptyList(); + } + List excludes = new ArrayList(); + for (Map.Entry 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."); @@ -317,21 +328,4 @@ public class AutoConfigurationImportSelector return Ordered.LOWEST_PRECEDENCE - 1; } - /** - * Bindable object used to get excludes. - */ - static class Excludes { - - private List exclude = new ArrayList(); - - public List getExclude() { - return this.exclude; - } - - public void setExclude(List excludes) { - this.exclude = excludes; - } - - } - }