Fix spring.application.exclude YAML property
`spring.application.exclude` is retrieved via the `RelaxedPropertyResolver` API explicitly and it does not have any standard API to retrieve a list of values. As a consequence that property could only be specified as a comma-separated value. This felt convoluted in YAML. `RelaxedPropertyResolver` has now a `getProperties` method that works with both comma-separated value and index elements (i.e. list). Closes gh-4352
This commit is contained in:
@@ -153,8 +153,12 @@ public class EnableAutoConfigurationImportSelector implements DeferredImportSele
|
||||
private List<String> 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<Object> raw = resolver.getProperties("exclude");
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (Object r : raw) {
|
||||
values.add(r.toString());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private List<String> sort(List<String> configurations) throws IOException {
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
},
|
||||
{
|
||||
"name": "spring.autoconfigure.exclude",
|
||||
"type": "java.lang.Class[]",
|
||||
"type": "java.util.List<java.lang.Class>",
|
||||
"description": "Auto-configuration classes to exclude."
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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() },
|
||||
|
||||
Reference in New Issue
Block a user