Skip to content

Commit 045fbee

Browse files
committed
Document need for $ separator when auto-config is nested
Closes gh-44298
1 parent 6760c39 commit 045fbee

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

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

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,8 +38,9 @@
3838
* {@link Configuration#proxyBeanMethods() proxyBeanMethods} is always {@code false}. They
3939
* are located using {@link ImportCandidates}.
4040
* <p>
41-
* Generally auto-configuration classes are marked as {@link Conditional @Conditional}
42-
* (most often using {@link ConditionalOnClass @ConditionalOnClass} and
41+
* Generally, auto-configuration classes are top-level classes that are marked as
42+
* {@link Conditional @Conditional} (most often using
43+
* {@link ConditionalOnClass @ConditionalOnClass} and
4344
* {@link ConditionalOnMissingBean @ConditionalOnMissingBean} annotations).
4445
*
4546
* @author Moritz Halbritter
@@ -76,28 +77,34 @@
7677
String value() default "";
7778

7879
/**
79-
* The auto-configure classes that should have not yet been applied.
80+
* The auto-configuration classes that should have not yet been applied.
8081
* @return the classes
8182
*/
8283
@AliasFor(annotation = AutoConfigureBefore.class, attribute = "value")
8384
Class<?>[] before() default {};
8485

8586
/**
86-
* The names of the auto-configure classes that should have not yet been applied.
87+
* The names of the auto-configuration classes that should have not yet been applied.
88+
* In the unusual case that an auto-configuration class is not a top-level class, its
89+
* name should use {@code $} to separate it from its containing class, for example
90+
* {@code com.example.Outer$NestedAutoConfiguration}.
8791
* @return the class names
8892
*/
8993
@AliasFor(annotation = AutoConfigureBefore.class, attribute = "name")
9094
String[] beforeName() default {};
9195

9296
/**
93-
* The auto-configure classes that should have already been applied.
97+
* The auto-configuration classes that should have already been applied.
9498
* @return the classes
9599
*/
96100
@AliasFor(annotation = AutoConfigureAfter.class, attribute = "value")
97101
Class<?>[] after() default {};
98102

99103
/**
100-
* The names of the auto-configure classes that should have already been applied.
104+
* The names of the auto-configuration classes that should have already been applied.
105+
* In the unusual case that an auto-configuration class is not a top-level class, its
106+
* class name should use {@code $} to separate it from its containing class, for
107+
* example {@code com.example.Outer$NestedAutoConfiguration}.
101108
* @return the class names
102109
*/
103110
@AliasFor(annotation = AutoConfigureAfter.class, attribute = "name")

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,14 +44,16 @@
4444
public @interface AutoConfigureAfter {
4545

4646
/**
47-
* The auto-configure classes that should have already been applied.
47+
* The auto-configuration classes that should have already been applied.
4848
* @return the classes
4949
*/
5050
Class<?>[] value() default {};
5151

5252
/**
53-
* The names of the auto-configure classes that should have already been applied.
54-
* @return the class names
53+
* The names of the auto-configuration classes that should have already been applied.
54+
* In the unusual case that an auto-configuration class is not a top-level class, its
55+
* class name should use {@code $} to separate it from its containing class, for
56+
* example {@code com.example.Outer$NestedAutoConfiguration}.
5557
* @since 1.2.2
5658
*/
5759
String[] name() default {};

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,10 @@
5050
Class<?>[] value() default {};
5151

5252
/**
53-
* The names of the auto-configure classes that should have not yet been applied.
53+
* The names of the auto-configuration classes that should have not yet been applied.
54+
* In the unusual case that an auto-configuration class is not a top-level class, its
55+
* class name should use {@code $} to separate it from its containing class, for
56+
* example {@code com.example.Outer$NestedAutoConfiguration}.
5457
* @return the class names
5558
* @since 1.2.2
5659
*/

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

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ com.mycorp.libx.autoconfigure.LibXWebAutoConfiguration
3636

3737
TIP: You can add comments to the imports file using the `#` character.
3838

39+
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`.
40+
3941
NOTE: Auto-configurations must be loaded _only_ by being named in the imports file.
4042
Make sure that they are defined in a specific package space and that they are never the target of component scanning.
4143
Furthermore, auto-configuration classes should not enable component scanning to find additional components.

0 commit comments

Comments
 (0)