org.springframework.context.annotation

## 注释类型 ComponentScan

-     @Retention(value=RUNTIME)
       @Target(value=TYPE)
       @Documented
       @Repeatable(value=ComponentScans.class)
      public @interface ComponentScan

  Configures component scanning directives for use with @`Configuration` classes. Provides support parallel with Spring 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 `AnnotationConfigApplicationContext`, 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.

  从以下版本开始:
    3.1
  作者:
    Chris Beams, Juergen Hoeller, Sam Brannen
  另请参阅:
    `Configuration`

- - ### 可选元素概要

    可选元素
    限定符和类型 | 可选元素和说明
    --- | ---
    `Class<?>[]` | `basePackageClasses` Type-safe alternative to `basePackages()` for specifying the packages to scan for annotated components.
    `String[]` | `basePackages` Base packages to scan for annotated components.
    `ComponentScan.Filter[]` | `excludeFilters` Specifies which types are not eligible for component scanning.
    `ComponentScan.Filter[]` | `includeFilters` Specifies which types are eligible for component scanning.
    `boolean` | `lazyInit` Specify whether scanned beans should be registered for lazy initialization.
    `Class<? extends org.springframework.beans.factory.support.BeanNameGenerator>` | `nameGenerator` The `BeanNameGenerator` class to be used for naming detected components within the Spring container.
    `String` | `resourcePattern` Controls the class files eligible for component detection.
    `ScopedProxyMode` | `scopedProxy` Indicates whether proxies should be generated for detected components, which may be necessary when using scopes in a proxy-style fashion.
    `Class<? extends ScopeMetadataResolver>` | `scopeResolver` The `ScopeMetadataResolver` to be used for resolving the scope of detected components.
    `boolean` | `useDefaultFilters` Indicates whether automatic detection of classes annotated with `@Component` `@Repository`, `@Service`, or `@Controller` should be enabled.
    `String[]` | `value` Alias for `basePackages()`.

- - ### 元素详细资料

    - #### value

          @AliasFor(value="basePackages")
          public abstract String[] value

      Alias for `basePackages()`.

      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

          @AliasFor(value="value")
          public abstract String[] 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

          public abstract Class<?>[] basePackageClasses

      Type-safe alternative to `basePackages()` 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

          public abstract Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGenerator

      The `BeanNameGenerator` class to be used for naming detected components within the Spring container.

      The default value of the `BeanNameGenerator` interface itself indicates that the scanner used to process this `@ComponentScan` annotation should use its inherited bean name generator, e.g. the default `AnnotationBeanNameGenerator` or any custom instance supplied to the application context at bootstrap time.

      另请参阅:
        `AnnotationConfigApplicationContext.setBeanNameGenerator(BeanNameGenerator)`
      默认值:
        org.springframework.beans.factory.support.BeanNameGenerator.class

  - - #### scopeResolver

          public abstract Class<? extends ScopeMetadataResolver> scopeResolver

      The `ScopeMetadataResolver` to be used for resolving the scope of detected components.
      默认值:
        org.springframework.context.annotation.AnnotationScopeMetadataResolver.class

  - - #### scopedProxy

          public abstract ScopedProxyMode scopedProxy

      Indicates 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()`.

      另请参阅:
        `ClassPathBeanDefinitionScanner.setScopedProxyMode(ScopedProxyMode)`
      默认值:
        org.springframework.context.annotation.ScopedProxyMode.DEFAULT

  - - #### resourcePattern

          public abstract String resourcePattern

      Controls the class files eligible for component detection.

      Consider use of `includeFilters()` and `excludeFilters()` for a more flexible approach.

      默认值:
        "**/*.class"

  - - #### useDefaultFilters

          public abstract boolean useDefaultFilters

      Indicates whether automatic detection of classes annotated with `@Component` `@Repository`, `@Service`, or `@Controller` should be enabled.
      默认值:
        true

  - - #### includeFilters

          public abstract ComponentScan.Filter[] includeFilters

      Specifies 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`).

      另请参阅:
        `resourcePattern()`, `useDefaultFilters()`
      默认值:
        {}

  - - #### excludeFilters

          public abstract ComponentScan.Filter[] excludeFilters

      Specifies which types are not eligible for component scanning.
      另请参阅:
        `resourcePattern()`
      默认值:
        {}

  - - #### lazyInit

          public abstract boolean lazyInit

      Specify whether scanned beans should be registered for lazy initialization.

      Default is `false`; switch this to `true` when desired.

      从以下版本开始:
        4.1
      默认值:
        false