Browse Source

Merge branch '3.3.x' into 3.4.x

Closes gh-44303
pull/44380/head
Andy Wilkinson 1 year ago
parent
commit
9fa40adb45
  1. 21
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfiguration.java
  2. 10
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureAfter.java
  3. 7
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java
  4. 2
      spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/developing-auto-configuration.adoc

21
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfiguration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,8 +38,9 @@ import org.springframework.core.annotation.AliasFor;
* {@link Configuration#proxyBeanMethods() proxyBeanMethods} is always {@code false}. They * {@link Configuration#proxyBeanMethods() proxyBeanMethods} is always {@code false}. They
* are located using {@link ImportCandidates}. * are located using {@link ImportCandidates}.
* <p> * <p>
* Generally auto-configuration classes are marked as {@link Conditional @Conditional} * Generally, auto-configuration classes are top-level classes that are marked as
* (most often using {@link ConditionalOnClass @ConditionalOnClass} and * {@link Conditional @Conditional} (most often using
* {@link ConditionalOnClass @ConditionalOnClass} and
* {@link ConditionalOnMissingBean @ConditionalOnMissingBean} annotations). * {@link ConditionalOnMissingBean @ConditionalOnMissingBean} annotations).
* *
* @author Moritz Halbritter * @author Moritz Halbritter
@ -76,28 +77,34 @@ public @interface AutoConfiguration {
String value() default ""; String value() default "";
/** /**
* The auto-configure classes that should have not yet been applied. * The auto-configuration classes that should have not yet been applied.
* @return the classes * @return the classes
*/ */
@AliasFor(annotation = AutoConfigureBefore.class, attribute = "value") @AliasFor(annotation = AutoConfigureBefore.class, attribute = "value")
Class<?>[] before() default {}; Class<?>[] before() default {};
/** /**
* The names of the auto-configure classes that should have not yet been applied. * The names of the auto-configuration classes that should have not yet been applied.
* In the unusual case that an auto-configuration class is not a top-level class, its
* name should use {@code $} to separate it from its containing class, for example
* {@code com.example.Outer$NestedAutoConfiguration}.
* @return the class names * @return the class names
*/ */
@AliasFor(annotation = AutoConfigureBefore.class, attribute = "name") @AliasFor(annotation = AutoConfigureBefore.class, attribute = "name")
String[] beforeName() default {}; String[] beforeName() default {};
/** /**
* The auto-configure classes that should have already been applied. * The auto-configuration classes that should have already been applied.
* @return the classes * @return the classes
*/ */
@AliasFor(annotation = AutoConfigureAfter.class, attribute = "value") @AliasFor(annotation = AutoConfigureAfter.class, attribute = "value")
Class<?>[] after() default {}; Class<?>[] after() default {};
/** /**
* The names of the auto-configure classes that should have already been applied. * The names of the auto-configuration classes that should have already been applied.
* In the unusual case that an auto-configuration class is not a top-level class, its
* class name should use {@code $} to separate it from its containing class, for
* example {@code com.example.Outer$NestedAutoConfiguration}.
* @return the class names * @return the class names
*/ */
@AliasFor(annotation = AutoConfigureAfter.class, attribute = "name") @AliasFor(annotation = AutoConfigureAfter.class, attribute = "name")

10
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureAfter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,14 +44,16 @@ import org.springframework.context.annotation.DependsOn;
public @interface AutoConfigureAfter { public @interface AutoConfigureAfter {
/** /**
* The auto-configure classes that should have already been applied. * The auto-configuration classes that should have already been applied.
* @return the classes * @return the classes
*/ */
Class<?>[] value() default {}; Class<?>[] value() default {};
/** /**
* The names of the auto-configure classes that should have already been applied. * The names of the auto-configuration classes that should have already been applied.
* @return the class names * In the unusual case that an auto-configuration class is not a top-level class, its
* class name should use {@code $} to separate it from its containing class, for
* example {@code com.example.Outer$NestedAutoConfiguration}.
* @since 1.2.2 * @since 1.2.2
*/ */
String[] name() default {}; String[] name() default {};

7
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -50,7 +50,10 @@ public @interface AutoConfigureBefore {
Class<?>[] value() default {}; Class<?>[] value() default {};
/** /**
* The names of the auto-configure classes that should have not yet been applied. * The names of the auto-configuration classes that should have not yet been applied.
* In the unusual case that an auto-configuration class is not a top-level class, its
* class name should use {@code $} to separate it from its containing class, for
* example {@code com.example.Outer$NestedAutoConfiguration}.
* @return the class names * @return the class names
* @since 1.2.2 * @since 1.2.2
*/ */

2
spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/developing-auto-configuration.adoc

@ -36,6 +36,8 @@ com.mycorp.libx.autoconfigure.LibXWebAutoConfiguration
TIP: You can add comments to the imports file using the `#` character. TIP: You can add comments to the imports file using the `#` character.
TIP: In the unusual case that an auto-configuration class is not a top-level class, its class name should use `$` to separate it from its containing class, for example `com.example.Outer$NestedAutoConfiguration`.
NOTE: Auto-configurations must be loaded _only_ by being named in the imports file. NOTE: Auto-configurations must be loaded _only_ by being named in the imports file.
Make sure that they are defined in a specific package space and that they are never the target of component scanning. Make sure that they are defined in a specific package space and that they are never the target of component scanning.
Furthermore, auto-configuration classes should not enable component scanning to find additional components. Furthermore, auto-configuration classes should not enable component scanning to find additional components.

Loading…
Cancel
Save