From e5e497ec3a954175ed9b7d95a7a4fd44d8f64991 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 19 Jan 2017 16:47:07 +0100 Subject: [PATCH] Document `@ImportAutoConfiguration#exclude` Closes gh-7862 --- .../boot/autoconfigure/ImportAutoConfiguration.java | 5 ++++- spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java index ce214673c2..af55f05b8d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -31,6 +31,9 @@ import org.springframework.core.annotation.AliasFor; * rules as {@code @EnableAutoConfiguration} but restricts the auto-configuration classes * to the specified set, rather than consulting {@code spring.factories}. *

+ * Can also be used to {@link #exclude()} specific auto-configuration classes such that + * they will never be applied. + *

* Generally, {@code @EnableAutoConfiguration} should be used in preference to this * annotation, however, {@code @ImportAutoConfiguration} can be useful in some situations * and especially when writing tests. diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index c773a776b2..821d0995d3 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -5383,6 +5383,10 @@ providing a `@...Test` annotation that loads the `ApplicationContext` and one or more `@AutoConfigure...` annotations that can be used to customize auto-configuration settings. +NOTE: Each slice loads a very restricted set of auto-configuration classes. If you need to +exclude one of them, most `@...Test` annotation provide an `excludeAutoConfiguration` +attribute. Alternatively, you can use `@ImportAutoConfiguration#exclude`. + TIP: It's also possible to use the `@AutoConfigure...` annotations with the standard `@SpringBootTest` annotation. You can use this combination if you're not interested in '`slicing`' your application but you want some of the auto-configured test beans.