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

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

Loading…
Cancel
Save