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 gh-3368
pull/3532/merge
Stephane Nicoll 9 years ago
parent ea4061fe99
commit 2c619232b3

@ -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.
* <p>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.
* <p>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 {};
}

@ -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]]

Loading…
Cancel
Save