类 ClassPathScanningCandidateComponentProvider
- 所有已实现的接口:
Aware,ResourceLoaderAware,cn.taketoday.core.env.EnvironmentCapable
- 直接已知子类:
ClassPathBeanDefinitionScanner
the index if it is available of scans the
classpath otherwise. Candidate components are identified by applying exclude and
include filters. AnnotationTypeFilter, AssignableTypeFilter include
filters on an annotation/superclass that are annotated with Indexed are
supported: if any other include filter is specified, the index is ignored and
classpath scanning is used instead.
This implementation is based on framework 's
MetadataReader
facility, backed by an ASM ClassReader.
- 从以下版本开始:
- 4.0 2021/12/9 21:33
- 作者:
- Mark Fisher, Juergen Hoeller, Ramnivas Laddad, Chris Beams, Stephane Nicoll, Harry Yang
-
字段概要
从类继承的字段 cn.taketoday.context.loader.ClassPathScanningComponentProvider
DEFAULT_RESOURCE_PATTERN, resourcePatternResolver -
构造器概要
构造器构造器说明ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) Create a ClassPathScanningCandidateComponentProvider with aStandardEnvironment.ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, cn.taketoday.core.env.Environment environment) Create a ClassPathScanningCandidateComponentProvider with the givenEnvironment. -
方法概要
修饰符和类型方法说明voidaddExcludeFilter(cn.taketoday.core.type.filter.TypeFilter excludeFilter) Add an exclude type filter to the front of the exclusion list.voidaddIncludeFilter(cn.taketoday.core.type.filter.TypeFilter includeFilter) Add an include type filter to the end of the inclusion list.findCandidateComponents(String basePackage) Scan the class path for candidate components.final cn.taketoday.core.env.Environmentprotected BeanDefinitionRegistryReturn theBeanDefinitionRegistryused by this scanner, if any.protected booleanisCandidateComponent(cn.taketoday.core.type.AnnotationMetadata metadata) Determine whether the given metadata qualifies as candidate.protected booleanisCandidateComponent(cn.taketoday.core.type.classreading.MetadataReader metadataReader, cn.taketoday.core.type.classreading.MetadataReaderFactory factory) Determine whether the given class does not match any exclude filter and does match at least one include filter.protected voidRegister the default filter for@Component.voidresetFilters(boolean useDefaultFilters) Reset the configured type filters.protected StringresolveBasePackage(String basePackage) Resolve the specified base package into a pattern specification for the package search path.voidscanCandidateComponents(String basePackage, MetadataReaderConsumer metadataReaderConsumer) Scan the class path for candidate components.voidsetCandidateComponentPredicate(Predicate<cn.taketoday.core.type.AnnotationMetadata> candidateComponentPredicate) Set thePredicateto use for candidate component testing.voidsetEnvironment(cn.taketoday.core.env.Environment environment) Set the Environment to use when resolving placeholders and evaluating@Conditional-annotated component classes.voidsetResourceLoader(cn.taketoday.core.io.ResourceLoader resourceLoader) Set theResourceLoaderto use for resource locations.从类继承的方法 cn.taketoday.context.loader.ClassPathScanningComponentProvider
clearCache, getMetadataReaderFactory, getPatternLocation, getResourceLoader, getResourcePrefix, scan, setMetadataReaderFactory, setResourcePattern, setResourcePrefix
-
构造器详细资料
-
ClassPathScanningCandidateComponentProvider
public ClassPathScanningCandidateComponentProvider() -
ClassPathScanningCandidateComponentProvider
public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) Create a ClassPathScanningCandidateComponentProvider with aStandardEnvironment.- 参数:
useDefaultFilters- whether to register the default filters for the@Component,@Repository,@Service, and@Controllerstereotype annotations- 另请参阅:
-
ClassPathScanningCandidateComponentProvider
public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, cn.taketoday.core.env.Environment environment) Create a ClassPathScanningCandidateComponentProvider with the givenEnvironment.- 参数:
useDefaultFilters- whether to register the default filters for the@Component,@Repository,@Service, and@Controllerstereotype annotationsenvironment- the Environment to use- 另请参阅:
-
-
方法详细资料
-
addIncludeFilter
public void addIncludeFilter(cn.taketoday.core.type.filter.TypeFilter includeFilter) Add an include type filter to the end of the inclusion list. -
addExcludeFilter
public void addExcludeFilter(cn.taketoday.core.type.filter.TypeFilter excludeFilter) Add an exclude type filter to the front of the exclusion list. -
resetFilters
public void resetFilters(boolean useDefaultFilters) Reset the configured type filters.- 参数:
useDefaultFilters- whether to re-register the default filters for the@Component,@Repository,@Service, and@Controllerstereotype annotations- 另请参阅:
-
registerDefaultFilters
protected void registerDefaultFilters()Register the default filter for@Component.This will implicitly register all annotations that have the
@Componentmeta-annotation including the@Repository,@Service, and@Controllerstereotype annotations.Also supports Jakarta EE's
ManagedBeanand JSR-330'sNamedannotations, if available. -
setEnvironment
public void setEnvironment(cn.taketoday.core.env.Environment environment) Set the Environment to use when resolving placeholders and evaluating@Conditional-annotated component classes.The default is a
StandardEnvironment.- 参数:
environment- the Environment to use
-
getEnvironment
public final cn.taketoday.core.env.Environment getEnvironment()- 指定者:
getEnvironment在接口中cn.taketoday.core.env.EnvironmentCapable
-
getRegistry
Return theBeanDefinitionRegistryused by this scanner, if any. -
setResourceLoader
public void setResourceLoader(@Nullable cn.taketoday.core.io.ResourceLoader resourceLoader) Set theResourceLoaderto use for resource locations. This will typically be aPatternResourceLoaderimplementation.Default is a
PathMatchingResourcePatternResolver, also capable of resource pattern resolving through theResourcePatternResolverinterface.- 指定者:
setResourceLoader在接口中ResourceLoaderAware- 覆盖:
setResourceLoader在类中ClassPathScanningComponentProvider- 参数:
resourceLoader- the ResourceLoader object to be used by this object- 另请参阅:
-
PatternResourceLoaderPathMatchingPatternResourceLoader
-
setCandidateComponentPredicate
public void setCandidateComponentPredicate(@Nullable Predicate<cn.taketoday.core.type.AnnotationMetadata> candidateComponentPredicate) Set thePredicateto use for candidate component testing. -
findCandidateComponents
Scan the class path for candidate components.- 参数:
basePackage- the package to check for annotated classes- 返回:
- a corresponding Set of autodetected bean definitions
-
scanCandidateComponents
public void scanCandidateComponents(String basePackage, MetadataReaderConsumer metadataReaderConsumer) throws IOException Scan the class path for candidate components.- 参数:
basePackage- the package to check for annotated classes- 抛出:
IOException
-
resolveBasePackage
Resolve the specified base package into a pattern specification for the package search path.The default implementation resolves placeholders against system properties, and converts a "."-based package path to a "/"-based resource path.
- 覆盖:
resolveBasePackage在类中ClassPathScanningComponentProvider- 参数:
basePackage- the base package as specified by the user- 返回:
- the pattern specification to be used for package searching
-
isCandidateComponent
protected boolean isCandidateComponent(cn.taketoday.core.type.classreading.MetadataReader metadataReader, cn.taketoday.core.type.classreading.MetadataReaderFactory factory) throws IOException Determine whether the given class does not match any exclude filter and does match at least one include filter.- 参数:
metadataReader- the ASM ClassReader for the classfactory- a factory for obtaining metadata readers for other classes (such as superclasses and interfaces)- 返回:
- whether the class qualifies as a candidate component
- 抛出:
IOException
-
isCandidateComponent
protected boolean isCandidateComponent(cn.taketoday.core.type.AnnotationMetadata metadata) Determine whether the given metadata qualifies as candidate.The default implementation checks whether the class is not an interface and not dependent on an enclosing class.
Can be overridden in subclasses.
- 参数:
metadata- the metadata to check- 返回:
- whether the bean definition qualifies as a candidate component
-