java.lang.Object | ||
↳ | org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider | |
↳ | org.springframework.context.annotation.ClassPathBeanDefinitionScanner |
A bean definition scanner that detects bean candidates on the classpath, registering corresponding bean definitions with a given registry (BeanFactory or ApplicationContext).
Candidate classes are detected through configurable type filters. The
default filters include classes that are annotated with Spring's
@Component
,
@Repository
,
@Service
, or
@Controller
stereotype.
Also supports Java EE 6's javax.annotation.ManagedBean and JSR-330's javax.inject.Named annotations, if available.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new ClassPathBeanDefinitionScanner for the given bean factory.
| |||||||||||
Create a new ClassPathBeanDefinitionScanner for the given bean factory.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the BeanDefinitionRegistry that this scanner operates on.
| |||||||||||
Perform a scan within the specified base packages.
| |||||||||||
Set the name-matching patterns for determining autowire candidates.
| |||||||||||
Set the defaults to use for detected beans.
| |||||||||||
Set the BeanNameGenerator to use for detected bean classes.
| |||||||||||
Specify whether to register annotation config post-processors.
| |||||||||||
Set the ScopeMetadataResolver to use for detected bean classes.
| |||||||||||
Specify the proxy behavior for non-singleton scoped beans.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Check the given candidate's bean name, determining whether the corresponding
bean definition needs to be registered or conflicts with an existing definition.
| |||||||||||
Perform a scan within the specified base packages,
returning the registered bean definitions.
| |||||||||||
Determine whether the given new bean definition is compatible with
the given existing bean definition.
| |||||||||||
Apply further settings to the given bean definition,
beyond the contents retrieved from scanning the component class.
| |||||||||||
Register the specified bean with the given registry.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.context.ResourceLoaderAware
| |||||||||||
From interface
org.springframework.core.env.EnvironmentCapable
|
Create a new ClassPathBeanDefinitionScanner for the given bean factory.
registry | the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry |
---|
Create a new ClassPathBeanDefinitionScanner for the given bean factory.
If the passed-in bean factory does not only implement the BeanDefinitionRegistry
interface but also the ResourceLoader interface, it will be used as default
ResourceLoader as well. This will usually be the case for
ApplicationContext
implementations.
If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a
PathMatchingResourcePatternResolver
.
If the the passed-in bean factory also implements EnvironmentCapable
its
environment will be used by this reader. Otherwise, the reader will initialize and
use a DefaultEnvironment. All ApplicationContext implementations are
EnvironmentCapable, while normal BeanFactory implementations are not.
registry | the BeanFactory to load bean definitions into, in the form of a BeanDefinitionRegistry |
---|---|
useDefaultFilters | whether to include the default filters for the
@Component ,
@Repository ,
@Service , and
@Controller stereotype
annotations. |
Return the BeanDefinitionRegistry that this scanner operates on.
Perform a scan within the specified base packages.
basePackages | the packages to check for annotated classes |
---|
Set the name-matching patterns for determining autowire candidates.
autowireCandidatePatterns | the patterns to match against |
---|
Set the defaults to use for detected beans.
Set the BeanNameGenerator to use for detected bean classes.
Default is a AnnotationBeanNameGenerator
.
Specify whether to register annotation config post-processors.
The default is to register the post-processors. Turn this off to be able to ignore the annotations or to process them differently.
Set the ScopeMetadataResolver to use for detected bean classes. Note that this will override any custom "scopedProxyMode" setting.
The default is an AnnotationScopeMetadataResolver
.
Specify the proxy behavior for non-singleton scoped beans. Note that this will override any custom "scopeMetadataResolver" setting.
The default is NO
.
Check the given candidate's bean name, determining whether the corresponding bean definition needs to be registered or conflicts with an existing definition.
beanName | the suggested name for the bean |
---|---|
beanDefinition | the corresponding bean definition |
true
if the bean can be registered as-is;
false
if it should be skipped because there is an
existing, compatible bean definition for the specified nameIllegalStateException | if an existing, incompatible bean definition has been found for the specified name |
---|
Perform a scan within the specified base packages, returning the registered bean definitions.
This method does not register an annotation config processor but rather leaves this up to the caller.
basePackages | the packages to check for annotated classes |
---|
null
)
Determine whether the given new bean definition is compatible with the given existing bean definition.
The default implementation simply considers them as compatible when the bean class name matches.
newDefinition | the new bean definition, originated from scanning |
---|---|
existingDefinition | the existing bean definition, potentially an explicitly defined one or a previously generated one from scanning |
Apply further settings to the given bean definition, beyond the contents retrieved from scanning the component class.
beanDefinition | the scanned bean definition |
---|---|
beanName | the generated bean name for the given bean |
Register the specified bean with the given registry.
Can be overridden in subclasses, e.g. to adapt the registration process or to register further bean definitions for each scanned bean.
definitionHolder | the bean definition plus bean name for the bean |
---|---|
registry | the BeanDefinitionRegistry to register the bean with |