spring-framework / org.springframework.context.annotation / ClassPathBeanDefinitionScanner

ClassPathBeanDefinitionScanner

open class ClassPathBeanDefinitionScanner : ClassPathScanningCandidateComponentProvider

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 org.springframework.stereotype.Component, org.springframework.stereotype.Repository, org.springframework.stereotype.Service, or org.springframework.stereotype.Controller stereotype.

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

Author
Mark Fisher

Author
Juergen Hoeller

Author
Chris Beams

Since
2.5

See Also
AnnotationConfigApplicationContext#scanorg.springframework.stereotype.Componentorg.springframework.stereotype.Repositoryorg.springframework.stereotype.Serviceorg.springframework.stereotype.Controller

Constructors

<init>

ClassPathBeanDefinitionScanner(registry: BeanDefinitionRegistry)

Create a new ClassPathBeanDefinitionScanner for the given bean factory.

ClassPathBeanDefinitionScanner(registry: BeanDefinitionRegistry, useDefaultFilters: Boolean)

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 org.springframework.context.ApplicationContext implementations.

If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a org.springframework.core.io.support.PathMatchingResourcePatternResolver.

If the passed-in bean factory also implements EnvironmentCapable its environment will be used by this reader. Otherwise, the reader will initialize and use a org.springframework.core.env.StandardEnvironment. All ApplicationContext implementations are EnvironmentCapable, while normal BeanFactory implementations are not.

ClassPathBeanDefinitionScanner(registry: BeanDefinitionRegistry, useDefaultFilters: Boolean, environment: Environment)

Create a new ClassPathBeanDefinitionScanner for the given bean factory and using the given Environment when evaluating bean definition profile metadata.

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 org.springframework.context.ApplicationContext implementations.

If given a plain BeanDefinitionRegistry, the default ResourceLoader will be a org.springframework.core.io.support.PathMatchingResourcePatternResolver.

ClassPathBeanDefinitionScanner(registry: BeanDefinitionRegistry, useDefaultFilters: Boolean, environment: Environment, resourceLoader: ResourceLoader)

Create a new ClassPathBeanDefinitionScanner for the given bean factory and using the given Environment when evaluating bean definition profile metadata.

Functions

getBeanDefinitionDefaults

open fun getBeanDefinitionDefaults(): BeanDefinitionDefaults

Return the defaults to use for detected beans (never null).

getRegistry

fun getRegistry(): BeanDefinitionRegistry

Return the BeanDefinitionRegistry that this scanner operates on.

scan

open fun scan(vararg basePackages: String): Int

Perform a scan within the specified base packages.

setAutowireCandidatePatterns

open fun setAutowireCandidatePatterns(vararg autowireCandidatePatterns: String): Unit

Set the name-matching patterns for determining autowire candidates.

setBeanDefinitionDefaults

open fun setBeanDefinitionDefaults(beanDefinitionDefaults: BeanDefinitionDefaults): Unit

Set the defaults to use for detected beans.

setBeanNameGenerator

open fun setBeanNameGenerator(beanNameGenerator: BeanNameGenerator): Unit

Set the BeanNameGenerator to use for detected bean classes.

Default is a AnnotationBeanNameGenerator.

setIncludeAnnotationConfig

open fun setIncludeAnnotationConfig(includeAnnotationConfig: Boolean): Unit

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.

setScopeMetadataResolver

open fun setScopeMetadataResolver(scopeMetadataResolver: ScopeMetadataResolver): Unit

Set the ScopeMetadataResolver to use for detected bean classes. Note that this will override any custom "scopedProxyMode" setting.

The default is an AnnotationScopeMetadataResolver.

setScopedProxyMode

open fun setScopedProxyMode(scopedProxyMode: ScopedProxyMode): Unit

Specify the proxy behavior for non-singleton scoped beans. Note that this will override any custom "scopeMetadataResolver" setting.

The default is ScopedProxyMode#NO.