Class AnnotationBeanDefinitionRegistryPostProcessor
java.lang.Object
io.microsphere.spring.beans.factory.annotation.AnnotationBeanDefinitionRegistryPostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanClassLoaderAware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.config.BeanFactoryPostProcessor
,org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
,org.springframework.context.EnvironmentAware
,org.springframework.context.ResourceLoaderAware
public abstract class AnnotationBeanDefinitionRegistryPostProcessor
extends Object
implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.beans.factory.BeanFactoryAware, org.springframework.context.EnvironmentAware, org.springframework.context.ResourceLoaderAware, org.springframework.beans.factory.BeanClassLoaderAware
An abstract class for the extension to
BeanDefinitionRegistryPostProcessor
, which will execute two main registration
methods orderly:
registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner, String[])
: Scan and register the primaryBeanDefinitions
that were annotated bythe supported annotation types
, and then return theMap
with bean name plus aliases if present and primaryAnnotatedBeanDefinitions
, it's allowed to be overrideregisterSecondaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner, Map, String[])
: it's mandatory to be override by the sub-class to register secondaryBeanDefinitions
if required
Example Usage
public class MyAnnotationBeanDefinitionRegistryPostProcessor extends AnnotationBeanDefinitionRegistryPostProcessor {
public MyAnnotationBeanDefinitionRegistryPostProcessor() {
super(MyAnnotation.class, "com.example.package");
}
protected Map<String, AnnotatedBeanDefinition> registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner,
String[] basePackages) {
// Custom logic to register primary bean definitions
return super.registerPrimaryBeanDefinitions(scanner, basePackages);
}
@Override
protected void registerSecondaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner,
Map<String, AnnotatedBeanDefinition> primaryBeanDefinitions,
String[] basePackages) {
// Logic to register secondary bean definitions based on primary ones
}
}
- Since:
- 1.0.0
- Author:
- Mercy
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationBeanDefinitionRegistryPostProcessor
(Class<? extends Annotation> primaryAnnotationType, Class<?>... basePackageClasses) AnnotationBeanDefinitionRegistryPostProcessor
(Class<? extends Annotation> primaryAnnotationType, Iterable<String> packagesToScan) AnnotationBeanDefinitionRegistryPostProcessor
(Class<? extends Annotation> primaryAnnotationType, String... packagesToScan) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addSupportedAnnotationType
(Class<? extends Annotation>... annotationTypes) protected static Annotation
getAnnotation
(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType) org.springframework.beans.factory.config.ConfigurableListableBeanFactory
org.springframework.core.env.ConfigurableEnvironment
org.springframework.core.io.ResourceLoader
Set<Class<? extends Annotation>>
final void
postProcessBeanDefinitionRegistry
(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) void
postProcessBeanFactory
(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) registerPrimaryBeanDefinitions
(ExposingClassPathBeanDefinitionScanner scanner, String[] basePackages) Scan and register the primaryBeanDefinitions
that were annotated bythe supported annotation types
, and then return theMap
with bean name plus aliases if present and primaryAnnotatedBeanDefinitions
.protected abstract void
registerSecondaryBeanDefinitions
(ExposingClassPathBeanDefinitionScanner scanner, Map<String, org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> primaryBeanDefinitions, String[] basePackages) Register the secondaryBeanDefinitions
protected String[]
resolveBasePackages
(Set<String> packagesToScan) Resolve the placeholders for the raw scanned packages to scanprotected final Class<?>
resolveBeanClass
(org.springframework.beans.factory.config.BeanDefinition beanDefinition) protected final Class<?>
resolveBeanClass
(org.springframework.beans.factory.config.BeanDefinitionHolder beanDefinitionHolder) void
setBeanClassLoader
(ClassLoader classLoader) void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) void
setClassLoader
(ClassLoader classLoader) void
setEnvironment
(org.springframework.core.env.Environment environment) void
setResourceLoader
(org.springframework.core.io.ResourceLoader resourceLoader)
-
Field Details
-
logger
protected final io.microsphere.logging.Logger logger
-
-
Constructor Details
-
AnnotationBeanDefinitionRegistryPostProcessor
public AnnotationBeanDefinitionRegistryPostProcessor(Class<? extends Annotation> primaryAnnotationType, Class<?>... basePackageClasses) -
AnnotationBeanDefinitionRegistryPostProcessor
public AnnotationBeanDefinitionRegistryPostProcessor(Class<? extends Annotation> primaryAnnotationType, String... packagesToScan) -
AnnotationBeanDefinitionRegistryPostProcessor
public AnnotationBeanDefinitionRegistryPostProcessor(Class<? extends Annotation> primaryAnnotationType, Iterable<String> packagesToScan)
-
-
Method Details
-
addSupportedAnnotationType
-
getAnnotation
protected static Annotation getAnnotation(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType) -
postProcessBeanDefinitionRegistry
public final void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) throws org.springframework.beans.BeansException - Specified by:
postProcessBeanDefinitionRegistry
in interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
- Throws:
org.springframework.beans.BeansException
-
registerPrimaryBeanDefinitions
protected Map<String,org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, String[] basePackages) Scan and register the primaryBeanDefinitions
that were annotated bythe supported annotation types
, and then return theMap
with bean name plus aliases if present and primaryAnnotatedBeanDefinitions
.Current method is allowed to be override by the sub-class to change the registration logic
- Parameters:
scanner
-ExposingClassPathBeanDefinitionScanner
basePackages
- the base packages to scan- Returns:
- the
Map
with bean name plus aliases if present and primaryAnnotatedBeanDefinitions
-
registerSecondaryBeanDefinitions
protected abstract void registerSecondaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, Map<String, org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> primaryBeanDefinitions, String[] basePackages) Register the secondaryBeanDefinitions
Current method is allowed to be override by the sub-class to change the registration logic
- Parameters:
scanner
- theExposingClassPathBeanDefinitionScanner
instanceprimaryBeanDefinitions
- theMap
with bean name plus aliases if present and primaryAnnotatedBeanDefinitions
, which may be emptybasePackages
- the base packages to scan
-
postProcessBeanFactory
public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
postProcessBeanFactory
in interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
- Specified by:
postProcessBeanFactory
in interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor
- Throws:
org.springframework.beans.BeansException
-
resolveBasePackages
Resolve the placeholders for the raw scanned packages to scan- Parameters:
packagesToScan
- the raw scanned packages to scan- Returns:
- non-null
-
resolveBeanClass
protected final Class<?> resolveBeanClass(org.springframework.beans.factory.config.BeanDefinitionHolder beanDefinitionHolder) -
resolveBeanClass
protected final Class<?> resolveBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition) -
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
getSupportedAnnotationTypes
-
getSupportedAnnotationTypeNames
-
getPackagesToScan
-
getBeanFactory
public org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory() -
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException - Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
- Throws:
org.springframework.beans.BeansException
-
getEnvironment
public org.springframework.core.env.ConfigurableEnvironment getEnvironment() -
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-
getResourceLoader
public org.springframework.core.io.ResourceLoader getResourceLoader() -
setResourceLoader
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) - Specified by:
setResourceLoader
in interfaceorg.springframework.context.ResourceLoaderAware
-
getClassLoader
-
setClassLoader
-