Class ClassPathScanningCandidateComponentProvider
- All Implemented Interfaces:
- Aware,- ResourceLoaderAware,- EnvironmentCapable
- Direct Known Subclasses:
- ClassPathBeanDefinitionScanner
Candidate components are identified by applying exclude and include filters.
 AnnotationTypeFilter and AssignableTypeFilter include filters
 for an annotation/target-type that is annotated with Indexed are
 supported: if any other include filter is specified, the index is ignored and
 classpath scanning is used instead.
 
This implementation is based on Spring's
 MetadataReader
 facility, backed by an ASM ClassReader.
- Since:
- 2.5
- Author:
- Mark Fisher, Juergen Hoeller, Ramnivas Laddad, Chris Beams, Stephane Nicoll, Sam Brannen
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedProtected constructor for flexible subclass initialization.ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) Create a ClassPathScanningCandidateComponentProvider with aStandardEnvironment.ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) Create a ClassPathScanningCandidateComponentProvider with the givenEnvironment.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddExcludeFilter(TypeFilter excludeFilter) Add an exclude type filter to the front of the exclusion list.voidaddIncludeFilter(TypeFilter includeFilter) Add an include type filter to the end of the inclusion list.voidClear the local metadata cache, if any, removing all cached class metadata.findCandidateComponents(String basePackage) Scan the component index or class path for candidate components.final EnvironmentReturn theEnvironmentassociated with this component.final MetadataReaderFactoryReturn the MetadataReaderFactory used by this component provider.protected BeanDefinitionRegistryReturn theBeanDefinitionRegistryused by this scanner, if any.final ResourceLoaderReturn the ResourceLoader that this component provider uses.protected booleanisCandidateComponent(AnnotatedBeanDefinition beanDefinition) Determine whether the given bean definition qualifies as a candidate component.protected booleanisCandidateComponent(MetadataReader metadataReader) Determine whether the given class does not match any exclude filter and does match at least one include filter.protected voidRegister the default filter for@Component.voidresetFilters(boolean useDefaultFilters) Reset the configured type filters.protected StringresolveBasePackage(String basePackage) Resolve the specified base package into a pattern specification for the package search path.voidsetEnvironment(Environment environment) Set the Environment to use when resolving placeholders and evaluating@Conditional-annotated component classes.voidsetMetadataReaderFactory(MetadataReaderFactory metadataReaderFactory) Set theMetadataReaderFactoryto use.voidsetResourceLoader(ResourceLoader resourceLoader) Set theResourceLoaderto use for resource locations.voidsetResourcePattern(String resourcePattern) Set the resource pattern to use when scanning the classpath.
- 
Field Details- 
IGNORE_CLASSFORMAT_PROPERTY_NAMESystem property that instructs Spring to ignore class format exceptions during classpath scanning, in particular for unsupported class file versions. By default, such a class format mismatch leads to a classpath scanning failure.- Since:
- 6.1.2
- See Also:
 
- 
logger
 
- 
- 
Constructor Details- 
ClassPathScanningCandidateComponentProviderprotected ClassPathScanningCandidateComponentProvider()Protected constructor for flexible subclass initialization.- Since:
- 4.3.6
 
- 
ClassPathScanningCandidateComponentProviderpublic ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) Create a ClassPathScanningCandidateComponentProvider with aStandardEnvironment.- Parameters:
- useDefaultFilters- whether to register the default filters for the- @Component,- @Repository,- @Service, and- @Controllerstereotype annotations
- See Also:
 
- 
ClassPathScanningCandidateComponentProviderpublic ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) Create a ClassPathScanningCandidateComponentProvider with the givenEnvironment.- Parameters:
- useDefaultFilters- whether to register the default filters for the- @Component,- @Repository,- @Service, and- @Controllerstereotype annotations
- environment- the Environment to use
- See Also:
 
 
- 
- 
Method Details- 
setResourcePatternSet the resource pattern to use when scanning the classpath. This value will be appended to each base package name.- See Also:
- 
- findCandidateComponents(String)
- DEFAULT_RESOURCE_PATTERN
 
 
- 
addIncludeFilterAdd an include type filter to the end of the inclusion list.
- 
addExcludeFilterAdd an exclude type filter to the front of the exclusion list.
- 
resetFilterspublic void resetFilters(boolean useDefaultFilters) Reset the configured type filters.- Parameters:
- useDefaultFilters- whether to re-register the default filters for the- @Component,- @Repository,- @Service, and- @Controllerstereotype annotations
- See Also:
 
- 
registerDefaultFiltersprotected void registerDefaultFilters()Register the default filter for@Component.This will implicitly register all annotations that have the @Componentmeta-annotation including the@Repository,@Service, and@Controllerstereotype annotations.Also supports Jakarta EE's ManagedBeanand JSR-330'sNamedannotations (as well as their pre-Jakartajavax.annotation.ManagedBeanandjavax.inject.Namedequivalents), if available.
- 
setEnvironmentSet the Environment to use when resolving placeholders and evaluating@Conditional-annotated component classes.The default is a StandardEnvironment.- Parameters:
- environment- the Environment to use
 
- 
getEnvironmentDescription copied from interface:EnvironmentCapableReturn theEnvironmentassociated with this component.- Specified by:
- getEnvironmentin interface- EnvironmentCapable
 
- 
getRegistryReturn theBeanDefinitionRegistryused by this scanner, if any.
- 
setResourceLoaderSet theResourceLoaderto use for resource locations. This will typically be aResourcePatternResolverimplementation.Default is a PathMatchingResourcePatternResolver, also capable of resource pattern resolving through theResourcePatternResolverinterface.- Specified by:
- setResourceLoaderin interface- ResourceLoaderAware
- Parameters:
- resourceLoader- the ResourceLoader object to be used by this object
- See Also:
 
- 
getResourceLoaderReturn the ResourceLoader that this component provider uses.
- 
setMetadataReaderFactorySet theMetadataReaderFactoryto use.Default is a CachingMetadataReaderFactoryfor the specified resource loader.Call this setter method after setResourceLoader(org.springframework.core.io.ResourceLoader)in order for the given MetadataReaderFactory to override the default factory.
- 
getMetadataReaderFactoryReturn the MetadataReaderFactory used by this component provider.
- 
findCandidateComponentsScan the component index or class path for candidate components.- Parameters:
- basePackage- the package to check for annotated classes
- Returns:
- a corresponding Set of autodetected bean definitions
 
- 
resolveBasePackageResolve the specified base package into a pattern specification for the package search path.The default implementation resolves placeholders against system properties, and converts a "."-based package path to a "/"-based resource path. - Parameters:
- basePackage- the base package as specified by the user
- Returns:
- the pattern specification to be used for package searching
 
- 
isCandidateComponentDetermine whether the given class does not match any exclude filter and does match at least one include filter.- Parameters:
- metadataReader- the ASM ClassReader for the class
- Returns:
- whether the class qualifies as a candidate component
- Throws:
- IOException
 
- 
isCandidateComponentDetermine whether the given bean definition qualifies as a candidate component.The default implementation checks whether the class is not dependent on an enclosing class as well as whether the class is either concrete (and therefore not an interface) or has @Lookupmethods.Can be overridden in subclasses. - Parameters:
- beanDefinition- the bean definition to check
- Returns:
- whether the bean definition qualifies as a candidate component
 
- 
clearCachepublic void clearCache()Clear the local metadata cache, if any, removing all cached class metadata.
 
-