diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java index 0a2a9b9511..858cc27d89 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelector.java @@ -153,8 +153,12 @@ public class EnableAutoConfigurationImportSelector implements DeferredImportSele private List getExcludeAutoConfigurationsProperty() { RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), "spring.autoconfigure."); - String[] exclude = resolver.getProperty("exclude", String[].class); - return (Arrays.asList(exclude == null ? new String[0] : exclude)); + Collection raw = resolver.getProperties("exclude"); + List values = new ArrayList(); + for (Object r : raw) { + values.add(r.toString()); + } + return values; } private List sort(List configurations) throws IOException { diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index b53578810c..f5034020e3 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -45,7 +45,7 @@ }, { "name": "spring.autoconfigure.exclude", - "type": "java.lang.Class[]", + "type": "java.util.List", "description": "Auto-configuration classes to exclude." }, { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java index 50853d3ea6..9d38661fd0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/EnableAutoConfigurationImportSelectorTests.java @@ -134,6 +134,21 @@ public class EnableAutoConfigurationImportSelectorTests { VelocityAutoConfiguration.class.getName())); } + @Test + public void severalPropertyYamlExclusionsAreApplied() { + configureExclusions(new String[0], new String[0], new String[0]); + this.environment.setProperty("spring.autoconfigure.exclude[0]", + FreeMarkerAutoConfiguration.class.getName()); + this.environment.setProperty("spring.autoconfigure.exclude[1]", + VelocityAutoConfiguration.class.getName()); + String[] imports = this.importSelector.selectImports(this.annotationMetadata); + assertThat(imports.length, + is(equalTo(getAutoConfigurationClassNames().size() - 2))); + assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions(), + containsInAnyOrder(FreeMarkerAutoConfiguration.class.getName(), + VelocityAutoConfiguration.class.getName())); + } + @Test public void combinedExclusionsAreApplied() { configureExclusions(new String[] { VelocityAutoConfiguration.class.getName() }, diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java index 3a85dc20a3..f868284b4c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/RelaxedPropertyResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 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,6 +16,9 @@ package org.springframework.boot.bind; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; import org.springframework.core.env.ConfigurableEnvironment; @@ -128,6 +131,21 @@ public class RelaxedPropertyResolver implements PropertyResolver { "Unable to resolve placeholders with relaxed properties"); } + /** + * Return the property values associated with the given key, or an empty + * list if the key cannot be resolved. + * @param key the property name to resolve + * @return the property values for that key + */ + public List getProperties(String key) { + Object[] singular = getProperty(key, Object[].class); + if (singular != null) { + return Arrays.asList(singular); + } + Map subProperties = getSubProperties(key); + return new ArrayList(subProperties.values()); + } + /** * Return a Map of all values from all underlying properties that start with the * specified key. NOTE: this method can only be used if the underlying resolver is a diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java index 78623a1bbc..009e630737 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2015 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. @@ -17,6 +17,7 @@ package org.springframework.boot.bind; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -30,6 +31,7 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.StandardEnvironment; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertEquals; @@ -39,6 +41,7 @@ import static org.junit.Assert.assertThat; * Tests for {@link RelaxedPropertyResolver}. * * @author Phillip Webb + * @author Stephane Nicoll */ public class RelaxedPropertyResolverTests { @@ -166,6 +169,34 @@ public class RelaxedPropertyResolverTests { assertThat(this.resolver.getProperty("foo-bar"), equalTo("spam")); } + @Test + public void commaSeparatedProperties() throws Exception { + this.source.put("x.y.foo", "1,2"); + this.resolver = new RelaxedPropertyResolver(this.environment, "x.y."); + List properties = this.resolver.getProperties("foo"); + assertThat(properties.size(), equalTo(2)); + assertThat(properties, contains((Object) "1", (Object) "2")); + } + + @Test + public void commaSeparatedPropertiesSingleValue() throws Exception { + this.source.put("x.y.foo", "1"); + this.resolver = new RelaxedPropertyResolver(this.environment, "x.y."); + List properties = this.resolver.getProperties("foo"); + assertThat(properties.size(), equalTo(1)); + assertThat(properties, contains((Object) "1")); + } + + @Test + public void indexedProperties() throws Exception { + this.source.put("x.y.foo[0]", "1"); + this.source.put("x.y.foo[1]", "2"); + this.resolver = new RelaxedPropertyResolver(this.environment, "x.y."); + List properties = this.resolver.getProperties("foo"); + assertThat(properties.size(), equalTo(2)); + assertThat(properties, contains((Object) "1", (Object) "2")); + } + @Test public void subProperties() throws Exception { this.source.put("x.y.my-sub.a.b", "1");