You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not enable @ConfigurationPropertiesScan be default
In 2.2.0, @ConfigurationPropertiesScan was enabled by default.
Unfortunately, this had the unexpected side-effect of breaking
conditional enablement of a @ConfigurationProperties class via
@EnableConfigurationProperties if the @ConfigurationProperties class
was in a package covered by scanning.
This commit remove @ConfigurationPropertiesScan from
@SpringBootApplication so that it is no longer enabled by default.
2.1.x users who rely upon such conditional enablement of
@ConfigurationProperties classes can now upgrade to 2.2.x without
having to make any changes. Users who do not have such a need and are
in a position to use configuration properties scanning can now opt-in
by adding @ConfigurationPropertiesScan to their main application class
alongside @SpringBootApplication.
Closesgh-18674
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java
+1-3Lines changed: 1 addition & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -40,8 +40,7 @@
40
40
* auto-configuration}, {@link ComponentScan component scanning}, and
41
41
* {@link ConfigurationPropertiesScan configuration properties scanning}. This is a
42
42
* convenience annotation that is equivalent to declaring {@code @Configuration},
43
-
* {@code @EnableAutoConfiguration}, {@code @ComponentScan}, and
Spring Boot provides an infrastructure to bind such types and register them as beans automatically.
921
-
If your application uses `@SpringBootApplication`, classes annotated with `@ConfigurationProperties` will automatically be scanned and registered as beans.
922
-
By default, scanning will occur from the package of the class that declares this annotation.
923
-
If you want to define specific packages to scan, you can do so using an explicit `@ConfigurationPropertiesScan` directive on your `@SpringBootApplication`-annotated class as shown in the following example:
920
+
Spring Boot provides infrastructure to bind `@ConfigurationProperties` types and register them as beans.
921
+
You can either enable configuration properties on a class-by-class basis or enable configuration property scanning that works in a similar manner to component scanning.
922
+
923
+
Sometimes, classes annotated with `@ConfigurationProperties` might not be suitable for scanning, for example, if you're developing your own auto-configuration or you want to enable them conditionally.
924
+
In these cases, specify the list of types to process using the `@EnableConfigurationProperties` annotation.
925
+
This can be done on any `@Configuration` class, as shown in the following example:
Sometimes, classes annotated with `@ConfigurationProperties` might not be suitable for scanning, for example, if you're developing your own auto-configuration.
934
-
In these cases, you can specify the list of types to process on any `@Configuration` class as shown in the following example:
935
+
To use configuration property scanning, add the `@ConfigurationPropertiesScan` annotation to your application.
936
+
Typically, it is added to the main application class that is annotated with `@SpringBootApplication` but it can be added to any `@Configuration` class.
937
+
By default, scanning will occur from the package of the class that declares the annotation.
938
+
If you want to define specific packages to scan, you can do so as shown in the following example:
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -298,7 +298,7 @@ The <<using-boot-using-springbootapplication-annotation, `@SpringBootApplication
298
298
For example, if you are writing a JPA application, the package of the `@SpringBootApplication` annotated class is used to search for `@Entity` items.
299
299
Using a root package also allows component scan to apply only on your project.
300
300
301
-
TIP: If you don't want to use `@SpringBootApplication`, the `@EnableAutoConfiguration` `@ComponentScan`, and `@ConfigurationPropertiesScan` annotations that it imports defines that behaviour so you can also use those instead.
301
+
TIP: If you don't want to use `@SpringBootApplication`, the `@EnableAutoConfiguration` and `@ComponentScan` annotations that it imports defines that behaviour so you can also use those instead.
302
302
303
303
The following listing shows a typical layout:
304
304
@@ -480,7 +480,6 @@ A single `@SpringBootApplication` annotation can be used to enable those three f
* `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<using-boot-structuring-your-code,the best practices>>)
483
-
* `@ConfigurationPropertiesScan`: enable `@ConfigurationProperties` scan on the package where the application is located (see <<using-boot-structuring-your-code,the best practices>>)
484
483
* `@Configuration`: allow to register extra beans in the context or import additional configuration classes
485
484
486
485
[source,java,indent=0]
@@ -490,7 +489,7 @@ A single `@SpringBootApplication` annotation can be used to enable those three f
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/ExampleWebClientApplication.java
0 commit comments