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 Jakarta EE's jakarta. and
JSR-330's jakarta. annotations, if available.
AnnotationConfigApplicationContext#scan, org.springframework.stereotype.Component , org.springframework.stereotype.Repository , org.springframework.stereotype.Service , org.springframework.stereotype.Controller
| Modifier and Type | Field and Description |
|---|---|
| private String[] | |
| private BeanDefinitionDefaults | |
| private BeanNameGenerator | |
| private boolean | |
| private final BeanDefinitionRegistry | |
| private ScopeMetadataResolver |
| Access | Constructor and Description |
|---|---|
| public | ClassPathBeanDefinitionScanner(BeanDefinitionRegistry
the registry)BeanFactory to load bean definitions into, in the form
of a BeanDefinitionRegistryCreate a new |
| public | ClassPathBeanDefinitionScanner(BeanDefinitionRegistry
the registry, boolean BeanFactory to load bean definitions into, in the form
of a BeanDefinitionRegistrywhether to include the default filters for the
useDefaultFilters)@Component,
@Repository,
@Service, and
@Controller stereotype annotationsCreate a new |
| public | ClassPathBeanDefinitionScanner(BeanDefinitionRegistry
the registry, boolean BeanFactory to load bean definitions into, in the form
of a BeanDefinitionRegistrywhether to include the default filters for the
useDefaultFilters, Environment @Component,
@Repository,
@Service, and
@Controller stereotype annotationsthe Spring environment)Environment to use when evaluating bean
definition profile metadataCreate a new |
| public | ClassPathBeanDefinitionScanner(BeanDefinitionRegistry
the registry, boolean BeanFactory to load bean definitions into, in the form
of a BeanDefinitionRegistrywhether to include the default filters for the
useDefaultFilters, Environment @Component,
@Repository,
@Service, and
@Controller stereotype annotationsthe Spring environment, ResourceLoader Environment to use when evaluating bean
definition profile metadatathe resourceLoader)ResourceLoader to useCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: 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 namethe suggested name for the bean beanName, BeanDefinition the corresponding bean definition beanDefinition)Check the given candidate's bean name, determining whether the corresponding bean definition needs to be registered or conflicts with an existing definition. |
| protected Set | |
| public BeanDefinitionDefaults | |
| private static Environment | getOrCreateEnvironment(BeanDefinitionRegistry registry)
Get the Environment from the given registry if possible, otherwise return a new StandardEnvironment. |
| public final BeanDefinitionRegistry | getRegistry()
Overrides org. Return the BeanDefinitionRegistry that this scanner operates on. |
| protected boolean | Returns: whether the definitions are considered as compatible, with the new definition to be skipped in favor of the existing definitionthe new bean definition, originated from scanning newDef, BeanDefinition the existing bean definition, potentially an
explicitly defined one or a previously generated one from scanning existingDef)Determine whether the given new bean definition is compatible with the given existing bean definition. |
| protected void | postProcessBeanDefinition(AbstractBeanDefinition
the scanned bean definition beanDefinition, String the generated bean name for the given bean beanName)Apply further settings to the given bean definition, beyond the contents retrieved from scanning the component class. |
| protected void | registerBeanDefinition(BeanDefinitionHolder
the bean definition plus bean name for the bean definitionHolder, BeanDefinitionRegistry the BeanDefinitionRegistry to register the bean with registry)Register the specified bean with the given registry. |
| public int | |
| public void | setAutowireCandidatePatterns(String...
the patterns to match against autowireCandidatePatterns)Set the name-matching patterns for determining autowire candidates. |
| public void | setBeanDefinitionDefaults(BeanDefinitionDefaults beanDefinitionDefaults)
Set the defaults to use for detected beans. |
| public void | setBeanNameGenerator(BeanNameGenerator beanNameGenerator)
Set the BeanNameGenerator to use for detected bean classes. |
| public void | setIncludeAnnotationConfig(boolean includeAnnotationConfig)
Specify whether to register annotation config post-processors. |
| public void | setScopedProxyMode(ScopedProxyMode scopedProxyMode)
Specify the proxy behavior for non-singleton scoped beans. |
| public void | setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver)
Set the ScopeMetadataResolver to use for detected bean classes. |
| autowireCandidatePatterns | back to summary |
|---|---|
| private String[] autowireCandidatePatterns
| |
| beanDefinitionDefaults | back to summary |
|---|---|
| private BeanDefinitionDefaults beanDefinitionDefaults | |
| beanNameGenerator | back to summary |
|---|---|
| private BeanNameGenerator beanNameGenerator | |
| includeAnnotationConfig | back to summary |
|---|---|
| private boolean includeAnnotationConfig | |
| registry | back to summary |
|---|---|
| private final BeanDefinitionRegistry registry | |
| scopeMetadataResolver | back to summary |
|---|---|
| private ScopeMetadataResolver scopeMetadataResolver | |
| ClassPathBeanDefinitionScanner | back to summary |
|---|---|
| public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry) Create a new
| |
| ClassPathBeanDefinitionScanner | back to summary |
|---|---|
| public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters) Create a new If the passed-in bean factory does not only implement the
If given a plain If the passed-in bean factory also implements
| |
| ClassPathBeanDefinitionScanner | back to summary |
|---|---|
| public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment) Create a new If the passed-in bean factory does not only implement the If given a plain
| |
| ClassPathBeanDefinitionScanner | back to summary |
|---|---|
| public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment, ResourceLoader resourceLoader) Create a new
| |
| checkCandidate | back to summary |
|---|---|
| protected boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException Check the given candidate's bean name, determining whether the corresponding bean definition needs to be registered or conflicts with an existing definition.
| |
| doScan | back to summary |
|---|---|
| protected Set 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.
| |
| getBeanDefinitionDefaults | back to summary |
|---|---|
| public BeanDefinitionDefaults getBeanDefinitionDefaults() Return the defaults to use for detected beans (never
| |
| getOrCreateEnvironment | back to summary |
|---|---|
| private static Environment getOrCreateEnvironment(BeanDefinitionRegistry registry) Get the Environment from the given registry if possible, otherwise return a new StandardEnvironment. | |
| getRegistry | back to summary |
|---|---|
| public final BeanDefinitionRegistry getRegistry() Overrides org. Return the BeanDefinitionRegistry that this scanner operates on.
| |
| isCompatible | back to summary |
|---|---|
| protected boolean isCompatible(BeanDefinition newDef, BeanDefinition existingDef) Determine whether the given new bean definition is compatible with the given existing bean definition. The default implementation considers them as compatible when the existing bean definition comes from the same source or from a non-scanning source.
| |
| postProcessBeanDefinition | back to summary |
|---|---|
| protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition, String beanName) Apply further settings to the given bean definition, beyond the contents retrieved from scanning the component class.
| |
| registerBeanDefinition | back to summary |
|---|---|
| protected void registerBeanDefinition(BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry) 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.
| |
| scan | back to summary |
|---|---|
| public int scan(String... basePackages) Perform a scan within the specified base packages.
| |
| setAutowireCandidatePatterns | back to summary |
|---|---|
| public void setAutowireCandidatePatterns(String... autowireCandidatePatterns) Set the name-matching patterns for determining autowire candidates.
| |
| setBeanDefinitionDefaults | back to summary |
|---|---|
| public void setBeanDefinitionDefaults(BeanDefinitionDefaults beanDefinitionDefaults) Set the defaults to use for detected beans.
| |
| setBeanNameGenerator | back to summary |
|---|---|
| public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) Set the BeanNameGenerator to use for detected bean classes. Default is a | |
| setIncludeAnnotationConfig | back to summary |
|---|---|
| public void setIncludeAnnotationConfig(boolean includeAnnotationConfig) 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. | |
| setScopedProxyMode | back to summary |
|---|---|
| public void setScopedProxyMode(ScopedProxyMode scopedProxyMode) Specify the proxy behavior for non-singleton scoped beans. Note that this will override any custom "scopeMetadataResolver" setting. The default is
| |
| setScopeMetadataResolver | back to summary |
|---|---|
| public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver) Set the ScopeMetadataResolver to use for detected bean classes. Note that this will override any custom "scopedProxyMode" setting. The default is an
| |