diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java index d283147b868..bc34228f597 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SpringBootApplication.java @@ -26,6 +26,7 @@ import java.lang.annotation.Target; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.AliasFor; /** * Indicates a {@link Configuration configuration} class that declares one or more @@ -61,4 +62,25 @@ public @interface SpringBootApplication { */ String[] excludeName() default {}; + /** + * Base packages to scan for annotated components. + *

Use {@link #scanBasePackageClasses} for a type-safe alternative to + * String-based package names. + * @return base packages to scan + * @since 1.3.0 + */ + @AliasFor(annotation = ComponentScan.class, attribute = "basePackages") + String[] scanBasePackages() default {}; + + /** + * Type-safe alternative to {@link #scanBasePackages} for specifying the packages + * to scan for annotated components. The package of each class specified will be scanned. + *

Consider creating a special no-op marker class or interface in each package + * that serves no purpose other than being referenced by this attribute. + * @return base packages to scan + * @since 1.3.0 + */ + @AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses") + Class[] scanBasePackageClasses() default {}; + } diff --git a/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc b/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc index 1b0a7126e3f..90a11cf8c17 100644 --- a/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc +++ b/spring-boot-docs/src/main/asciidoc/using-spring-boot.adoc @@ -696,6 +696,9 @@ The `@SpringBootApplication` annotation is equivalent to using `@Configuration`, } ---- +NOTE: `@SpringBootApplication` also provides aliases to customize the attributes of +`@EnableAutoConfiguration` and `@ComponentScan`. + [[using-boot-running-your-application]]