Class BeanCapableImportCandidate
java.lang.Object
io.microsphere.spring.context.annotation.BeanCapableImportCandidate
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.context.EnvironmentAware,org.springframework.context.ResourceLoaderAware
- Direct Known Subclasses:
AnnotatedPropertySourceLoader
public abstract class BeanCapableImportCandidate
extends Object
implements org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.context.EnvironmentAware, org.springframework.context.ResourceLoaderAware
The
@Import candidate is an instance of ImportSelector or ImportBeanDefinitionRegistrar
and not a regular Spring bean, which only invokes BeanClassLoaderAware, BeanFactoryAware,
EnvironmentAware, and ResourceLoaderAware contracts in order if they are implemented, thus it will
not be populated and
initialized .
The current abstract implementation is a template class supports the Spring bean lifecycles :
population,
initialization, and
destroy, the sub-class must implement
the interface ImportSelector or ImportBeanDefinitionRegistrar, and can't override those methods:
setBeanClassLoader(ClassLoader)setBeanFactory(BeanFactory)setEnvironment(Environment)setResourceLoader(ResourceLoader)
Example Usage
public class MyImportRegistrar extends BeanCapableImportCandidate implements ImportBeanDefinitionRegistrar {
private final Logger logger = getLogger(this.getClass());
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
logger.info("Registering beans from custom registrar");
registry.registerBeanDefinition("myBean", new RootBeanDefinition(MyBean.class));
}
}
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
AbstractAutowireCapableBeanFactory.populateBean(String, RootBeanDefinition, BeanWrapper)AutowireCapableBeanFactory.initializeBean(Object, String)ConfigurableBeanFactory.destroyBean(String, Object)ApplicationContextAwareProcessor
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.beans.factory.config.ConfigurableListableBeanFactoryprotected ClassLoaderprotected org.springframework.core.env.ConfigurableEnvironmentprotected final io.microsphere.logging.Loggerprotected org.springframework.core.io.ResourceLoader -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal org.springframework.beans.factory.config.ConfigurableListableBeanFactoryTheConfigurableListableBeanFactoryinstancefinal ClassLoaderGet theClassLoaderinstancefinal org.springframework.core.env.ConfigurableEnvironmentTheConfigurableEnvironmentinstancefinal org.springframework.core.io.ResourceLoaderTheResourceLoaderinstancefinal voidsetBeanClassLoader(ClassLoader classLoader) final voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) final voidsetEnvironment(org.springframework.core.env.Environment environment) final voidsetResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
-
Field Details
-
logger
protected final io.microsphere.logging.Logger logger -
classLoader
-
beanFactory
protected org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory -
environment
protected org.springframework.core.env.ConfigurableEnvironment environment -
resourceLoader
protected org.springframework.core.io.ResourceLoader resourceLoader
-
-
Constructor Details
-
BeanCapableImportCandidate
public BeanCapableImportCandidate()
-
-
Method Details
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
setBeanFactory
public final 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
-
setEnvironment
public final void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
setResourceLoader
public final void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) - Specified by:
setResourceLoaderin interfaceorg.springframework.context.ResourceLoaderAware
-
getClassLoader
Get theClassLoaderinstance- Returns:
- non-null
-
getBeanFactory
@Nonnull public final org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory()TheConfigurableListableBeanFactoryinstance- Returns:
- non-null
-
getEnvironment
@Nonnull public final org.springframework.core.env.ConfigurableEnvironment getEnvironment()TheConfigurableEnvironmentinstance- Returns:
- non-null
-
getResourceLoader
@Nonnull public final org.springframework.core.io.ResourceLoader getResourceLoader()TheResourceLoaderinstance- Returns:
- non-null
-