Skip to content

Commit 2c61923

Browse files
committed
Add ComponentScan aliases on SpringBootApplication
Add aliases for `@ComponentScan`attributes on `@SpringBootApplication` so that it is possible to customize how the component scan should be applied on the project. Previously, one would have to revert to `@EnableAutoConfiguration` to achieve the same result. Closes spring-projectsgh-3368
1 parent ea4061f commit 2c61923

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java

+22
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.context.annotation.Bean;
2727
import org.springframework.context.annotation.ComponentScan;
2828
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.core.annotation.AliasFor;
2930

3031
/**
3132
* Indicates a {@link Configuration configuration} class that declares one or more
@@ -61,4 +62,25 @@
6162
*/
6263
String[] excludeName() default {};
6364

65+
/**
66+
* Base packages to scan for annotated components.
67+
* <p>Use {@link #scanBasePackageClasses} for a type-safe alternative to
68+
* String-based package names.
69+
* @return base packages to scan
70+
* @since 1.3.0
71+
*/
72+
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
73+
String[] scanBasePackages() default {};
74+
75+
/**
76+
* Type-safe alternative to {@link #scanBasePackages} for specifying the packages
77+
* to scan for annotated components. The package of each class specified will be scanned.
78+
* <p>Consider creating a special no-op marker class or interface in each package
79+
* that serves no purpose other than being referenced by this attribute.
80+
* @return base packages to scan
81+
* @since 1.3.0
82+
*/
83+
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
84+
Class<?>[] scanBasePackageClasses() default {};
85+
6486
}

spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ The `@SpringBootApplication` annotation is equivalent to using `@Configuration`,
696696
}
697697
----
698698

699+
NOTE: `@SpringBootApplication` also provides aliases to customize the attributes of
700+
`@EnableAutoConfiguration` and `@ComponentScan`.
701+
699702

700703

701704
[[using-boot-running-your-application]]

0 commit comments

Comments
 (0)