类 ClassPathScanningCandidateComponentProvider

java.lang.Object
cn.taketoday.context.loader.ClassPathScanningComponentProvider
cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider
所有已实现的接口:
Aware, ResourceLoaderAware, cn.taketoday.core.env.EnvironmentCapable
直接已知子类:
ClassPathBeanDefinitionScanner

public class ClassPathScanningCandidateComponentProvider extends ClassPathScanningComponentProvider implements cn.taketoday.core.env.EnvironmentCapable
A component provider that provides candidate components from a base package. Can use 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
  • 构造器详细资料

    • ClassPathScanningCandidateComponentProvider

      public ClassPathScanningCandidateComponentProvider()
    • ClassPathScanningCandidateComponentProvider

      public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters)
      Create a ClassPathScanningCandidateComponentProvider with a StandardEnvironment.
      参数:
      useDefaultFilters - whether to register the default filters for the @Component, @Repository, @Service, and @Controller stereotype annotations
      另请参阅:
    • ClassPathScanningCandidateComponentProvider

      public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, cn.taketoday.core.env.Environment environment)
      Create a ClassPathScanningCandidateComponentProvider with the given Environment.
      参数:
      useDefaultFilters - whether to register the default filters for the @Component, @Repository, @Service, and @Controller stereotype annotations
      environment - 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 @Controller stereotype annotations
      另请参阅:
    • registerDefaultFilters

      protected void registerDefaultFilters()
      Register the default filter for @Component.

      This will implicitly register all annotations that have the @Component meta-annotation including the @Repository, @Service, and @Controller stereotype annotations.

      Also supports Jakarta EE's ManagedBean and JSR-330's Named annotations, 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

      @Nullable protected BeanDefinitionRegistry getRegistry()
      Return the BeanDefinitionRegistry used by this scanner, if any.
    • setResourceLoader

      public void setResourceLoader(@Nullable cn.taketoday.core.io.ResourceLoader resourceLoader)
      Set the ResourceLoader to use for resource locations. This will typically be a PatternResourceLoader implementation.

      Default is a PathMatchingResourcePatternResolver, also capable of resource pattern resolving through the ResourcePatternResolver interface.

      指定者:
      setResourceLoader 在接口中 ResourceLoaderAware
      覆盖:
      setResourceLoader 在类中 ClassPathScanningComponentProvider
      参数:
      resourceLoader - the ResourceLoader object to be used by this object
      另请参阅:
      • PatternResourceLoader
      • PathMatchingPatternResourceLoader
    • setCandidateComponentPredicate

      public void setCandidateComponentPredicate(@Nullable Predicate<cn.taketoday.core.type.AnnotationMetadata> candidateComponentPredicate)
      Set the Predicate to use for candidate component testing.
    • findCandidateComponents

      public Set<AnnotatedBeanDefinition> findCandidateComponents(String basePackage)
      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

      protected String resolveBasePackage(String basePackage)
      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 class
      factory - 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