Add excludeName to EnableAutoConfiguration
Allow user to exclude an auto-configuration class by specifying the fully qualified name instead of the class reference. Closes gh-2660
This commit is contained in:
@@ -43,8 +43,9 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
* <p>
|
||||
* Auto-configuration tries to be as intelligent as possible and will back-away as you
|
||||
* define more of your own configuration. You can always manually {@link #exclude()} any
|
||||
* configuration that you never want to apply. Auto-configuration is always applied after
|
||||
* user-defined beans have been registered.
|
||||
* configuration that you never want to apply (use {@link #excludeName()} if you don't
|
||||
* have access to them). Auto-configuration is always applied after user-defined beans
|
||||
* have been registered.
|
||||
* <p>
|
||||
* The package of the class that is annotated with {@code @EnableAutoConfiguration} has
|
||||
* specific significance and is often used as a 'default'. For example, it will be used
|
||||
@@ -59,6 +60,7 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
* {@link ConditionalOnMissingBean @ConditionalOnMissingBean} annotations).
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
* @see ConditionalOnBean
|
||||
* @see ConditionalOnMissingBean
|
||||
* @see ConditionalOnClass
|
||||
@@ -78,4 +80,11 @@ public @interface EnableAutoConfiguration {
|
||||
*/
|
||||
Class<?>[] exclude() default {};
|
||||
|
||||
/**
|
||||
* Exclude specific auto-configuration class names such that they will never be
|
||||
* applied.
|
||||
* @return the class names to exclude
|
||||
*/
|
||||
String[] excludeName() default {};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @see EnableAutoConfiguration
|
||||
*/
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
@@ -73,9 +74,8 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector,
|
||||
this.beanClassLoader)));
|
||||
|
||||
// Remove those specifically disabled
|
||||
List<String> excluded = Arrays.asList(attributes.getStringArray("exclude"));
|
||||
factories.removeAll(excluded);
|
||||
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
|
||||
exclude(Arrays.asList(attributes.getStringArray("exclude")), factories);
|
||||
exclude(Arrays.asList(attributes.getStringArray("excludeName")), factories);
|
||||
|
||||
// Sort
|
||||
factories = new AutoConfigurationSorter(this.resourceLoader)
|
||||
@@ -88,6 +88,11 @@ class EnableAutoConfigurationImportSelector implements DeferredImportSelector,
|
||||
}
|
||||
}
|
||||
|
||||
private void exclude(List<String> excluded, List<String> factories) {
|
||||
factories.removeAll(excluded);
|
||||
ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* {@code @EnableAutoConfiguration} and {@code @ComponentScan}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@@ -52,4 +53,11 @@ public @interface SpringBootApplication {
|
||||
*/
|
||||
Class<?>[] exclude() default {};
|
||||
|
||||
/**
|
||||
* Exclude specific auto-configuration class names such that they will never be
|
||||
* applied.
|
||||
* @return the class names to exclude
|
||||
*/
|
||||
String[] excludeName() default {};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user