From d9882f2c88dad1e9995d4849974a9d6dc025bd03 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 15 Jul 2020 10:48:01 +0100 Subject: [PATCH] Clarify the effects of ordering auto-configuration classes Closes gh-22337 --- .../boot/autoconfigure/AutoConfigureAfter.java | 11 ++++++++++- .../boot/autoconfigure/AutoConfigureBefore.java | 13 +++++++++++-- .../boot/autoconfigure/AutoConfigureOrder.java | 10 +++++++++- .../src/main/asciidoc/spring-boot-features.adoc | 3 +++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureAfter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureAfter.java index 3f9ab0eacb5..e3bb47f88cf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureAfter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureAfter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -22,9 +22,18 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; + /** * Hint for that an {@link EnableAutoConfiguration auto-configuration} should be applied * after other specified auto-configuration classes. + *

+ * As with standard {@link Configuration @Configuration} classes, the order in which + * auto-configuration classes are applied only affects the order in which their beans are + * defined. The order in which those beans are subsequently created is unaffected and is + * determined by each bean's dependencies and any {@link DependsOn @DependsOn} + * relationships. * * @author Phillip Webb * @since 1.0.0 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java index 34c7191abf2..5da0b3a3f95 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -22,9 +22,18 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; + /** - * Hint for that an {@link EnableAutoConfiguration auto-configuration} should be applied + * Hint that an {@link EnableAutoConfiguration auto-configuration} should be applied * before other specified auto-configuration classes. + *

+ * As with standard {@link Configuration @Configuration} classes, the order in which + * auto-configuration classes are applied only affects the order in which their beans are + * defined. The order in which those beans are subsequently created is unaffected and is + * determined by each bean's dependencies and any {@link DependsOn @DependsOn} + * relationships. * * @author Phillip Webb * @since 1.0.0 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java index 3c0092e070d..ac9266cd904 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureOrder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -23,6 +23,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -31,6 +33,12 @@ import org.springframework.core.annotation.Order; * annotation. Allows auto-configuration classes to be ordered among themselves without * affecting the order of configuration classes passed to * {@link AnnotationConfigApplicationContext#register(Class...)}. + *

+ * As with standard {@link Configuration @Configuration} classes, the order in which + * auto-configuration classes are applied only affects the order in which their beans are + * defined. The order in which those beans are subsequently created is unaffected and is + * determined by each bean's dependencies and any {@link DependsOn @DependsOn} + * relationships. * * @author Andy Wilkinson * @since 1.3.0 diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index e2ee1109340..aa7777402ac 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -7313,6 +7313,9 @@ For example, if you provide web-specific configuration, your class may need to b If you want to order certain auto-configurations that should not have any direct knowledge of each other, you can also use `@AutoConfigureOrder`. That annotation has the same semantic as the regular `@Order` annotation but provides a dedicated order for auto-configuration classes. +As with standard `@Configuration` classes, the order in which auto-configuration classes are applied only affects the order in which their beans are defined. +The order in which those beans are subsequently created is unaffected and is determined by each bean's dependencies and any `@DependsOn` relationships. + [[boot-features-condition-annotations]]