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 java.lang.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.BeanClassLoaderAwareAn abstract class for the extension toBeanDefinitionRegistryPostProcessor, which will execute two main registration methods orderly:registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner, String[]): Scan and register the primaryBeanDefinitionsthat were annotated bythe supported annotation types, and then return theMapwith 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 secondaryBeanDefinitionsif required
Example Usage
{@code public class MyAnnotationBeanDefinitionRegistryPostProcessor extends AnnotationBeanDefinitionRegistryPostProcessor { public MyAnnotationBeanDefinitionRegistryPostProcessor() { super(MyAnnotation.class, "com.example.package"); } protected MapregisterPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, String[] basePackages) { // Custom logic to register primary bean definitions return super.registerPrimaryBeanDefinitions(scanner, basePackages); } - Since:
- 1.0.0
- Author:
- Mercy
-
-
Field Summary
Fields Modifier and Type Field Description protected io.microsphere.logging.Loggerlogger
-
Constructor Summary
Constructors Constructor Description AnnotationBeanDefinitionRegistryPostProcessor(java.lang.Class<? extends java.lang.annotation.Annotation> primaryAnnotationType, java.lang.Class<?>... basePackageClasses)AnnotationBeanDefinitionRegistryPostProcessor(java.lang.Class<? extends java.lang.annotation.Annotation> primaryAnnotationType, java.lang.Iterable<java.lang.String> packagesToScan)AnnotationBeanDefinitionRegistryPostProcessor(java.lang.Class<? extends java.lang.annotation.Annotation> primaryAnnotationType, java.lang.String... packagesToScan)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddSupportedAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation>... annotationTypes)protected static java.lang.annotation.AnnotationgetAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)org.springframework.beans.factory.config.ConfigurableListableBeanFactorygetBeanFactory()java.lang.ClassLoadergetClassLoader()org.springframework.core.env.ConfigurableEnvironmentgetEnvironment()java.util.Set<java.lang.String>getPackagesToScan()org.springframework.core.io.ResourceLoadergetResourceLoader()protected java.util.Set<java.lang.String>getSupportedAnnotationTypeNames()java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>getSupportedAnnotationTypes()voidpostProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)protected java.util.Map<java.lang.String,org.springframework.beans.factory.annotation.AnnotatedBeanDefinition>registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, java.lang.String[] basePackages)Scan and register the primaryBeanDefinitionsthat were annotated bythe supported annotation types, and then return theMapwith bean name plus aliases if present and primaryAnnotatedBeanDefinitions.protected abstract voidregisterSecondaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, java.util.Map<java.lang.String,org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> primaryBeanDefinitions, java.lang.String[] basePackages)Register the secondaryBeanDefinitionsprotected java.lang.String[]resolveBasePackages(java.util.Set<java.lang.String> packagesToScan)Resolve the placeholders for the raw scanned packages to scanprotected java.lang.Class<?>resolveBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition)protected java.lang.Class<?>resolveBeanClass(org.springframework.beans.factory.config.BeanDefinitionHolder beanDefinitionHolder)voidsetBeanClassLoader(java.lang.ClassLoader classLoader)voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)voidsetClassLoader(java.lang.ClassLoader classLoader)voidsetEnvironment(org.springframework.core.env.Environment environment)voidsetResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
-
-
-
Constructor Detail
-
AnnotationBeanDefinitionRegistryPostProcessor
public AnnotationBeanDefinitionRegistryPostProcessor(java.lang.Class<? extends java.lang.annotation.Annotation> primaryAnnotationType, java.lang.Class<?>... basePackageClasses)
-
AnnotationBeanDefinitionRegistryPostProcessor
public AnnotationBeanDefinitionRegistryPostProcessor(java.lang.Class<? extends java.lang.annotation.Annotation> primaryAnnotationType, java.lang.String... packagesToScan)
-
AnnotationBeanDefinitionRegistryPostProcessor
public AnnotationBeanDefinitionRegistryPostProcessor(java.lang.Class<? extends java.lang.annotation.Annotation> primaryAnnotationType, java.lang.Iterable<java.lang.String> packagesToScan)
-
-
Method Detail
-
addSupportedAnnotationType
public void addSupportedAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation>... annotationTypes)
-
getAnnotation
protected static java.lang.annotation.Annotation getAnnotation(java.lang.reflect.AnnotatedElement annotatedElement, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
postProcessBeanDefinitionRegistry
public final void postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) throws org.springframework.beans.BeansException- Specified by:
postProcessBeanDefinitionRegistryin interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor- Throws:
org.springframework.beans.BeansException
-
registerPrimaryBeanDefinitions
protected java.util.Map<java.lang.String,org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, java.lang.String[] basePackages)
Scan and register the primaryBeanDefinitionsthat were annotated bythe supported annotation types, and then return theMapwith 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-ExposingClassPathBeanDefinitionScannerbasePackages- the base packages to scan- Returns:
- the
Mapwith bean name plus aliases if present and primaryAnnotatedBeanDefinitions
-
registerSecondaryBeanDefinitions
protected abstract void registerSecondaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, java.util.Map<java.lang.String,org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> primaryBeanDefinitions, java.lang.String[] basePackages)
Register the secondaryBeanDefinitionsCurrent method is allowed to be override by the sub-class to change the registration logic
- Parameters:
scanner- theExposingClassPathBeanDefinitionScannerinstanceprimaryBeanDefinitions- theMapwith 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:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor- Throws:
org.springframework.beans.BeansException
-
resolveBasePackages
protected java.lang.String[] resolveBasePackages(java.util.Set<java.lang.String> packagesToScan)
Resolve the placeholders for the raw scanned packages to scan- Parameters:
packagesToScan- the raw scanned packages to scan- Returns:
- non-null
-
resolveBeanClass
protected final java.lang.Class<?> resolveBeanClass(org.springframework.beans.factory.config.BeanDefinitionHolder beanDefinitionHolder)
-
resolveBeanClass
protected final java.lang.Class<?> resolveBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition)
-
setBeanClassLoader
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
getSupportedAnnotationTypes
public java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> getSupportedAnnotationTypes()
-
getSupportedAnnotationTypeNames
protected java.util.Set<java.lang.String> getSupportedAnnotationTypeNames()
-
getPackagesToScan
public java.util.Set<java.lang.String> 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:
setBeanFactoryin 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:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
getResourceLoader
public org.springframework.core.io.ResourceLoader getResourceLoader()
-
setResourceLoader
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
- Specified by:
setResourceLoaderin interfaceorg.springframework.context.ResourceLoaderAware
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
-
-