Fix parsing of spring.autoconfigure.exclude property

This commits makes sure that `AutoConfigureImportSelector` properly
parses comma separated lists that contain additional spaces.

Closes gh-8220
pull/8274/head
Stephane Nicoll 8 years ago
parent e891fe0584
commit 45a91fca31

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -222,8 +223,8 @@ public class AutoConfigurationImportSelector
String name = entry.getKey(); String name = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
if (name.isEmpty() || name.startsWith("[") && value != null) { if (name.isEmpty() || name.startsWith("[") && value != null) {
excludes.addAll( excludes.addAll(new HashSet<String>(Arrays.asList(StringUtils
StringUtils.commaDelimitedListToSet(String.valueOf(value))); .tokenizeToStringArray(String.valueOf(value), ","))));
} }
} }
return excludes; return excludes;

@ -130,11 +130,15 @@ public class AutoConfigurationImportSelectorTests {
this.environment.setProperty("spring.autoconfigure.exclude", this.environment.setProperty("spring.autoconfigure.exclude",
FreeMarkerAutoConfiguration.class.getName() + "," FreeMarkerAutoConfiguration.class.getName() + ","
+ MustacheAutoConfiguration.class.getName()); + MustacheAutoConfiguration.class.getName());
String[] imports = selectImports(BasicEnableAutoConfiguration.class); testSeveralPropertyExclusionsAreApplied();
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); }
assertThat(this.importSelector.getLastEvent().getExclusions()).contains(
FreeMarkerAutoConfiguration.class.getName(), @Test
MustacheAutoConfiguration.class.getName()); public void severalPropertyExclusionsAreAppliedWithExtraSpaces() {
this.environment.setProperty("spring.autoconfigure.exclude",
FreeMarkerAutoConfiguration.class.getName() + " , "
+ MustacheAutoConfiguration.class.getName() + " ");
testSeveralPropertyExclusionsAreApplied();
} }
@Test @Test
@ -143,6 +147,10 @@ public class AutoConfigurationImportSelectorTests {
FreeMarkerAutoConfiguration.class.getName()); FreeMarkerAutoConfiguration.class.getName());
this.environment.setProperty("spring.autoconfigure.exclude[1]", this.environment.setProperty("spring.autoconfigure.exclude[1]",
MustacheAutoConfiguration.class.getName()); MustacheAutoConfiguration.class.getName());
testSeveralPropertyExclusionsAreApplied();
}
private void testSeveralPropertyExclusionsAreApplied() {
String[] imports = selectImports(BasicEnableAutoConfiguration.class); String[] imports = selectImports(BasicEnableAutoConfiguration.class);
assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2); assertThat(imports).hasSize(getAutoConfigurationClassNames().size() - 2);
assertThat(this.importSelector.getLastEvent().getExclusions()).contains( assertThat(this.importSelector.getLastEvent().getExclusions()).contains(

Loading…
Cancel
Save