|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
public class ClassPathScanningCandidateComponentProvider
A component provider that scans the classpath from a base package. It then applies exclude and include filters to the resulting classes to find candidates.
This implementation is based on Spring's
MetadataReader
facility, backed by an ASM ClassReader
.
MetadataReaderFactory
,
AnnotationMetadata
,
ScannedGenericBeanDefinition
Field Summary | |
---|---|
private static java.lang.String |
DEFAULT_RESOURCE_PATTERN
|
private java.util.List<TypeFilter> |
excludeFilters
|
private java.util.List<TypeFilter> |
includeFilters
|
protected Log |
logger
|
private MetadataReaderFactory |
metadataReaderFactory
|
private java.lang.String |
resourcePattern
|
private ResourcePatternResolver |
resourcePatternResolver
|
Constructor Summary | |
---|---|
ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters)
Create a ClassPathScanningCandidateComponentProvider. |
Method Summary | |
---|---|
void |
addExcludeFilter(TypeFilter excludeFilter)
Add an exclude type filter to the front of the exclusion list. |
void |
addIncludeFilter(TypeFilter includeFilter)
Add an include type filter to the end of the inclusion list. |
java.util.Set<BeanDefinition> |
findCandidateComponents(java.lang.String basePackage)
Scan the class path for candidate components. |
ResourceLoader |
getResourceLoader()
Return the ResourceLoader that this component provider uses. |
protected boolean |
isCandidateComponent(AnnotatedBeanDefinition beanDefinition)
Determine whether the given bean definition qualifies as candidate. |
protected boolean |
isCandidateComponent(MetadataReader metadataReader)
Determine whether the given class does not match any exclude filter and does match at least one include filter. |
protected void |
registerDefaultFilters()
Register the default filter for @Component . |
void |
resetFilters(boolean useDefaultFilters)
Reset the configured type filters. |
protected java.lang.String |
resolveBasePackage(java.lang.String basePackage)
Resolve the specified base package into a pattern specification for the package search path. |
void |
setResourceLoader(ResourceLoader resourceLoader)
Set the ResourceLoader to use for resource locations. |
void |
setResourcePattern(java.lang.String resourcePattern)
Set the resource pattern to use when scanning the classpath. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String DEFAULT_RESOURCE_PATTERN
protected final Log logger
private ResourcePatternResolver resourcePatternResolver
private MetadataReaderFactory metadataReaderFactory
private java.lang.String resourcePattern
private final java.util.List<TypeFilter> includeFilters
private final java.util.List<TypeFilter> excludeFilters
Constructor Detail |
---|
public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters)
useDefaultFilters
- whether to register the default filters for the
@Component
, @Repository
,
@Service
, and @Controller
stereotype annotationsregisterDefaultFilters()
Method Detail |
---|
public void setResourceLoader(ResourceLoader resourceLoader)
Default is PathMatchingResourcePatternResolver, also capable of resource pattern resolving through the ResourcePatternResolver interface.
setResourceLoader
in interface ResourceLoaderAware
resourceLoader
- ResourceLoader object to be used by this objectResourcePatternResolver
,
PathMatchingResourcePatternResolver
public final ResourceLoader getResourceLoader()
public void setResourcePattern(java.lang.String resourcePattern)
findCandidateComponents(String)
,
DEFAULT_RESOURCE_PATTERN
public void addIncludeFilter(TypeFilter includeFilter)
public void addExcludeFilter(TypeFilter excludeFilter)
public void resetFilters(boolean useDefaultFilters)
useDefaultFilters
- whether to re-register the default filters for
the @Component
, @Repository
,
@Service
, and @Controller
stereotype annotationsregisterDefaultFilters()
protected void registerDefaultFilters()
@Component
.
This will implicitly register all annotations that have the
@Component
meta-annotation including the
@Repository
, @Service
, and
@Controller
stereotype annotations.
Also supports Java EE 6's javax.annotation.ManagedBean
and
JSR-330's javax.inject.Named
annotations, if available.
public java.util.Set<BeanDefinition> findCandidateComponents(java.lang.String basePackage)
basePackage
- the package to check for annotated classes
protected java.lang.String resolveBasePackage(java.lang.String basePackage)
The default implementation resolves placeholders against system properties, and converts a "."-based package path to a "/"-based resource path.
basePackage
- the base package as specified by the user
protected boolean isCandidateComponent(MetadataReader metadataReader) throws java.io.IOException
metadataReader
- the ASM ClassReader for the class
java.io.IOException
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition)
The default implementation checks whether the class is concrete (i.e. not abstract and not an interface). Can be overridden in subclasses.
beanDefinition
- the bean definition to check
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |