org.springframework.context.annotation

## 类 ClassPathScanningCandidateComponentProvider

- java.lang.Object
- - org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, ResourceLoaderAware, org.springframework.core.env.EnvironmentCapable
  直接已知子类:
    ClassPathBeanDefinitionScanner

      public class ClassPathScanningCandidateComponentProvider
      extends Object
      implements org.springframework.core.env.EnvironmentCapable, ResourceLoaderAware

  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 Spring's `MetadataReader` facility, backed by an ASM `ClassReader`.

  从以下版本开始:
    2.5
  作者:
    Mark Fisher, Juergen Hoeller, Ramnivas Laddad, Chris Beams, Stephane Nicoll
  另请参阅:
    `MetadataReaderFactory`, `AnnotationMetadata`, `ScannedGenericBeanDefinition`, `CandidateComponentsIndex`

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `protected Log` | `logger`

  - ### 构造器概要

    构造器
    限定符 | 构造器和说明
    --- | ---
    `protected` | `ClassPathScanningCandidateComponentProvider()` Protected constructor for flexible subclass initialization.
    `` | `ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters)` Create a ClassPathScanningCandidateComponentProvider with a `StandardEnvironment`.
    `` | `ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, org.springframework.core.env.Environment environment)` Create a ClassPathScanningCandidateComponentProvider with the given `Environment`.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `addExcludeFilter(org.springframework.core.type.filter.TypeFilter excludeFilter)` Add an exclude type filter to the front of the exclusion list.
    `void` | `addIncludeFilter(org.springframework.core.type.filter.TypeFilter includeFilter)` Add an include type filter to the end of the inclusion list.
    `void` | `clearCache()` Clear the local metadata cache, if any, removing all cached class metadata.
    `Set<org.springframework.beans.factory.config.BeanDefinition>` | `findCandidateComponents(String basePackage)` Scan the class path for candidate components.
    `org.springframework.core.env.Environment` | `getEnvironment()`
    `org.springframework.core.type.classreading.MetadataReaderFactory` | `getMetadataReaderFactory()` Return the MetadataReaderFactory used by this component provider.
    `protected org.springframework.beans.factory.support.BeanDefinitionRegistry` | `getRegistry()` Return the `BeanDefinitionRegistry` used by this scanner, if any.
    `org.springframework.core.io.ResourceLoader` | `getResourceLoader()` Return the ResourceLoader that this component provider uses.
    `protected boolean` | `isCandidateComponent(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition beanDefinition)` Determine whether the given bean definition qualifies as candidate.
    `protected boolean` | `isCandidateComponent(org.springframework.core.type.classreading.MetadataReader metadataReader)` Determine whether the given class does not match any exclude filter and does match at least one include filter.
    `protected void` | `registerDefaultFilters()` 这也是为啥我们标注了@Compent @Repository @Service @Controller 能够被识别解析 Also supports Java EE 6's `ManagedBean` and JSR-330's `Named` annotations, if available.
    `void` | `resetFilters(boolean useDefaultFilters)` Reset the configured type filters.
    `protected String` | `resolveBasePackage(String basePackage)` Resolve the specified base package into a pattern specification for the package search path.
    `void` | `setEnvironment(org.springframework.core.env.Environment environment)` Set the Environment to use when resolving placeholders and evaluating `@Conditional`-annotated component classes.
    `void` | `setMetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory metadataReaderFactory)` Set the `MetadataReaderFactory` to use.
    `void` | `setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)` Set the `ResourceLoader` to use for resource locations.
    `void` | `setResourcePattern(String resourcePattern)` Set the resource pattern to use when scanning the classpath.

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 字段详细资料

    - #### logger

          protected final Log logger

  - ### 构造器详细资料

    - #### ClassPathScanningCandidateComponentProvider

          protected ClassPathScanningCandidateComponentProvider()

      Protected constructor for flexible subclass initialization.
      从以下版本开始:
        4.3.6

    - #### 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
      另请参阅:
        `registerDefaultFilters()`

    - #### ClassPathScanningCandidateComponentProvider

          public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters,
                                                             org.springframework.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
      另请参阅:
        `registerDefaultFilters()`

  - ### 方法详细资料

    - #### setResourcePattern

          public void setResourcePattern(String resourcePattern)

      Set the resource pattern to use when scanning the classpath. This value will be appended to each base package name.
      另请参阅:
        `findCandidateComponents(String)`, `DEFAULT_RESOURCE_PATTERN`

    - #### addIncludeFilter

          public void addIncludeFilter(org.springframework.core.type.filter.TypeFilter includeFilter)

      Add an include type filter to the end of the inclusion list.

    - #### addExcludeFilter

          public void addExcludeFilter(org.springframework.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()`

    - #### registerDefaultFilters

          protected void registerDefaultFilters()

      这也是为啥我们标注了@Compent @Repository @Service @Controller 能够被识别解析

      Also supports Java EE 6's `ManagedBean` and JSR-330's `Named` annotations, if available.

    - #### setEnvironment

          public void setEnvironment(org.springframework.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 org.springframework.core.env.Environment getEnvironment()

      指定者:
        `getEnvironment` 在接口中 `org.springframework.core.env.EnvironmentCapable`

    - #### getRegistry

          @Nullable
          protected org.springframework.beans.factory.support.BeanDefinitionRegistry getRegistry()

      Return the `BeanDefinitionRegistry` used by this scanner, if any.

    - #### setResourceLoader

          public void setResourceLoader(@Nullable
                                        org.springframework.core.io.ResourceLoader resourceLoader)

      Set the `ResourceLoader` to use for resource locations. This will typically be a `ResourcePatternResolver` implementation.

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

      指定者:
        `setResourceLoader` 在接口中 `ResourceLoaderAware`
      参数:
        `resourceLoader` - the ResourceLoader object to be used by this object
      另请参阅:
        `ResourcePatternResolver`, `PathMatchingResourcePatternResolver`

    - #### getResourceLoader

          public final org.springframework.core.io.ResourceLoader getResourceLoader()

      Return the ResourceLoader that this component provider uses.

    - #### setMetadataReaderFactory

          public void setMetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory metadataReaderFactory)

      Set the `MetadataReaderFactory` to use.

      Default is a `CachingMetadataReaderFactory` for the specified resource loader.

      Call this setter method after `setResourceLoader(org.springframework.core.io.ResourceLoader)` in order for the given MetadataReaderFactory to override the default factory.

    - #### getMetadataReaderFactory

          public final org.springframework.core.type.classreading.MetadataReaderFactory getMetadataReaderFactory()

      Return the MetadataReaderFactory used by this component provider.

    - #### findCandidateComponents

          public Set<org.springframework.beans.factory.config.BeanDefinition> 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

    - #### 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.

      参数:
        `basePackage` - the base package as specified by the user
      返回:
        the pattern specification to be used for package searching

    - #### isCandidateComponent

          protected boolean isCandidateComponent(org.springframework.core.type.classreading.MetadataReader metadataReader)
                                          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
      返回:
        whether the class qualifies as a candidate component
      抛出:
        `IOException`

    - #### isCandidateComponent

          protected boolean isCandidateComponent(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition beanDefinition)

      Determine whether the given bean definition 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.

      参数:
        `beanDefinition` - the bean definition to check
      返回:
        whether the bean definition qualifies as a candidate component

    - #### clearCache

          public void clearCache()

      Clear the local metadata cache, if any, removing all cached class metadata.