Annotation Interface ComponentScan
Configuration classes.
Provides support parallel with Framework XML's <context:component-scan> element.
Either basePackageClasses() or basePackages() (or its alias
value()) may be specified to define specific packages to scan. If specific
packages are not defined, scanning will occur from the package of the
class that declares this annotation.
Note that the <context:component-scan> element has an
annotation-config attribute; however, this annotation does not. This is because
in almost all cases when using @ComponentScan, default annotation config
processing (e.g. processing @Autowired and friends) is assumed. Furthermore,
when using StandardApplicationContext, annotation config processors are
always registered, meaning that any attempt to disable them at the
@ComponentScan level would be ignored.
See @Configuration's Javadoc for usage examples.
- 作者:
- Chris Beams, Juergen Hoeller, Sam Brannen, TODAY 2019-11-13 23:52
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static @interfaceDeclares the type filter to be used as an include filter or exclude filter. -
可选元素概要
可选元素修饰符和类型可选元素说明Class<?>[]Type-safe alternative tobasePackages()for specifying the packages to scan for annotated components.String[]Base packages to scan for annotated components.Specifies which types are not eligible for component scanning.Specifies which types are eligible for component scanning.booleanSpecify whether scanned beans should be registered for lazy initialization.Class<? extends BeanNameGenerator>TheBeanNameGeneratorclass to be used for naming detected components within the IoC.Controls the class files eligible for component detection.Indicates whether proxies should be generated for detected components, which may be necessary when using scopes in a proxy-style fashion.Class<? extends ScopeMetadataResolver>TheScopeMetadataResolverto be used for resolving the scope of detected components.booleanIndicates whether automatic detection of classes annotated with@Component@Repository,@Service, or@Controllershould be enabled.String[]Alias forbasePackages().
-
元素详细资料
-
value
Alias forbasePackages().Allows for more concise annotation declarations if no other attributes are needed — for example,
@ComponentScan("org.my.pkg")instead of@ComponentScan(basePackages = "org.my.pkg").- 默认值:
- {}
-
basePackages
Base packages to scan for annotated components.value()is an alias for (and mutually exclusive with) this attribute.Use
basePackageClasses()for a type-safe alternative to String-based package names.- 默认值:
- {}
-
basePackageClasses
Class<?>[] basePackageClassesType-safe alternative tobasePackages()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.
- 默认值:
- {}
-
nameGenerator
Class<? extends BeanNameGenerator> nameGeneratorTheBeanNameGeneratorclass to be used for naming detected components within the IoC.The default value of the
BeanNameGeneratorinterface itself indicates that the scanner used to process this@ComponentScanannotation should use its inherited bean name generator, e.g. the defaultAnnotationBeanNameGeneratoror any custom instance supplied to the application context at bootstrap time.- 默认值:
- cn.taketoday.beans.factory.support.BeanNameGenerator.class
-
scopeResolver
Class<? extends ScopeMetadataResolver> scopeResolverTheScopeMetadataResolverto be used for resolving the scope of detected components.- 默认值:
- cn.taketoday.context.loader.ScopeMetadataResolver.class
-
scopedProxy
ScopedProxyMode scopedProxyIndicates whether proxies should be generated for detected components, which may be necessary when using scopes in a proxy-style fashion.The default is defer to the default behavior of the component scanner used to execute the actual scan.
Note that setting this attribute overrides any value set for
scopeResolver().- 默认值:
- DEFAULT
-
resourcePattern
String resourcePatternControls the class files eligible for component detection.Consider use of
includeFilters()andexcludeFilters()for a more flexible approach.- 默认值:
- "**/*.class"
-
useDefaultFilters
boolean useDefaultFiltersIndicates whether automatic detection of classes annotated with@Component@Repository,@Service, or@Controllershould be enabled.- 默认值:
- true
-
includeFilters
ComponentScan.Filter[] includeFiltersSpecifies which types are eligible for component scanning.Further narrows the set of candidate components from everything in
basePackages()to everything in the base packages that matches the given filter or filters.Note that these filters will be applied in addition to the default filters, if specified. Any type under the specified base packages which matches a given filter will be included, even if it does not match the default filters (i.e. is not annotated with
@Component).- 默认值:
- {}
-
excludeFilters
ComponentScan.Filter[] excludeFiltersSpecifies which types are not eligible for component scanning.- 另请参阅:
- 默认值:
- {}
-
lazyInit
boolean lazyInitSpecify whether scanned beans should be registered for lazy initialization.Default is
false; switch this totruewhen desired.- 默认值:
- false
-