org.springframework.config.java.plugin.context
Annotation Type ComponentScan


@Retention(value=RUNTIME)
@Target(value=TYPE)
@Documented
public @interface ComponentScan

Scans the classpath for annotated components that will be auto-registered as Spring beans. By default, the Spring-provided @Component, @Repository, @Service, and @Controller stereotypes will be detected.

Represents support equivalent to Spring XML's <context:component-scan/> element. attributes of this annotation are in a 1:1 relationship (as much as is technically possible) with the attributes and child elements found in component-scan.

Note: This annotation implies the effects of the AnnotationDrivenConfig annotation, activating @Required, @Autowired, @PostConstruct, @PreDestroy, @Resource, @PersistenceContext and @PersistenceUnit annotations in the component classes, which is usually desired for autodetected components (without external configuration). Turn off the 'annotationConfig' attribute to deactivate this default behavior, for example in order to use custom BeanPostProcessor definitions for handling those annotations.

Note: Placeholders in package paths is NOT supported at this time (a deviation from the XML support for <context:component-scan/>).

Author:
Chris Beams

Required Element Summary
 java.lang.String[] value
          One or more base packages to scan.
 
Optional Element Summary
 boolean annotationConfig
          Whether to enable annotation-driven configuration during component scanning.
 java.lang.Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGenerator
          Specifies the bean naming strategy for naming a component-scanned bean definition.
 java.lang.String resourcePattern
          Defaults to empty string, will delegate to default resource pattern defined by ClassPathScanningCandidateComponentProvider.
 org.springframework.context.annotation.ScopedProxyMode scopedProxy
           
 java.lang.Class<? extends org.springframework.context.annotation.ScopeMetadataResolver> scopeResolver
          Specifies the strategy for determining the scope of a component-scanned bean definition.
 boolean useDefaultFilters
          Whether to use Spring's default set of filters.
 

Element Detail

value

public abstract java.lang.String[] value
One or more base packages to scan. Ant-style wildcarding is supported.

scopedProxy

public abstract org.springframework.context.annotation.ScopedProxyMode scopedProxy
Default:
org.springframework.context.annotation.ScopedProxyMode.NO

annotationConfig

public abstract boolean annotationConfig
Whether to enable annotation-driven configuration during component scanning. Defaults to true as these features go hand-in-hand, but disabling is supported. Note that disabling may cause component scanning to fail, particularly in the case of @Autowired constructors.

Default:
true

resourcePattern

public abstract java.lang.String resourcePattern
Defaults to empty string, will delegate to default resource pattern defined by ClassPathScanningCandidateComponentProvider.

See Also:
ClassPathScanningCandidateComponentProvider.DEFAULT_RESOURCE_PATTERN
Default:
""

useDefaultFilters

public abstract boolean useDefaultFilters
Whether to use Spring's default set of filters. True by default. If true, default filters will be applied even if explicit #includeFilters() or #excludeFilters() are specified.

See Also:
ClassPathScanningCandidateComponentProvider.registerDefaultFilters()
Default:
true

nameGenerator

public abstract java.lang.Class<? extends org.springframework.beans.factory.support.BeanNameGenerator> nameGenerator
Specifies the bean naming strategy for naming a component-scanned bean definition. Defaults to AnnotationBeanNameGenerator.

See Also:
ClassPathBeanDefinitionScanner.setBeanNameGenerator(BeanNameGenerator)
Default:
org.springframework.context.annotation.AnnotationBeanNameGenerator.class

scopeResolver

public abstract java.lang.Class<? extends org.springframework.context.annotation.ScopeMetadataResolver> scopeResolver
Specifies the strategy for determining the scope of a component-scanned bean definition. Defaults to AnnotationScopeMetadataResolver, which understands the @Scope annotation.

See Also:
ClassPathBeanDefinitionScanner.setScopeMetadataResolver(ScopeMetadataResolver)
Default:
org.springframework.context.annotation.AnnotationScopeMetadataResolver.class