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 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
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 TypeMethodDescriptionvoidaddSupportedAnnotationType(Class<? extends Annotation>... annotationTypes) protected static AnnotationgetAnnotation(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType) org.springframework.beans.factory.config.ConfigurableListableBeanFactoryorg.springframework.core.env.ConfigurableEnvironmentorg.springframework.core.io.ResourceLoaderSet<Class<? extends Annotation>>final voidpostProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) registerPrimaryBeanDefinitions(ExposingClassPathBeanDefinitionScanner scanner, 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, Map<String, org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> primaryBeanDefinitions, String[] basePackages) Register the secondaryBeanDefinitionsprotected 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) voidsetBeanClassLoader(ClassLoader classLoader) voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) voidsetClassLoader(ClassLoader classLoader) voidsetEnvironment(org.springframework.core.env.Environment environment) voidsetResourceLoader(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:
postProcessBeanDefinitionRegistryin 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 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, Map<String, org.springframework.beans.factory.annotation.AnnotatedBeanDefinition> primaryBeanDefinitions, 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.support.BeanDefinitionRegistryPostProcessor- Specified by:
postProcessBeanFactoryin 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:
setBeanClassLoaderin 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:
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
-
setClassLoader
-