Class AnnotatedInjectionBeanPostProcessor
java.lang.Object
io.microsphere.spring.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
io.microsphere.spring.beans.factory.annotation.AnnotatedInjectionBeanPostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanClassLoaderAware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.config.BeanPostProcessor
,org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
,org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
,org.springframework.context.EnvironmentAware
,org.springframework.core.Ordered
,org.springframework.core.PriorityOrdered
public class AnnotatedInjectionBeanPostProcessor
extends InstantiationAwareBeanPostProcessorAdapter
implements org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor, org.springframework.core.PriorityOrdered, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.context.EnvironmentAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
The generic
BeanPostProcessor
implementation to support the dependency injection for the customized annotations.
As a substitution, besides the core features of AutowiredAnnotationBeanPostProcessor
, AnnotatedInjectionBeanPostProcessor
also supports:
The dependency injection with multiple types of annotations
-
Annotation Features Enhancement:
setClassValuesAsString(boolean)
: whether to turn Class references into Strings (for compatibility with or to preserve them as Class referencessetNestedAnnotationsAsMap(boolean)
: whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility withAnnotationMetadata
or to preserve them as Annotation instancessetIgnoreDefaultValue(boolean)
: whether ignore default value or not: whether try merged annotation or not</li> </ul> </li> <li>{@link #setCacheSize(int) The size of the metadata cache}</li> </ul>
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
AutowiredAnnotationBeanPostProcessor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AnnotationInjectionMetadata.InjectedElement
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotatedInjectionBeanPostProcessor
(Class<? extends Annotation> annotationType, Class<? extends Annotation>... otherAnnotationTypes) AnnotatedInjectionBeanPostProcessor
(Collection<Class<? extends Annotation>> annotationTypes) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
destroy()
final Constructor<?>[]
determineCandidateConstructors
(Class<?> beanClass, String beanName) protected boolean
determineRequiredStatus
(org.springframework.core.annotation.AnnotationAttributes attributes) Determine if the annotated field or method requires its dependency.protected final org.springframework.core.annotation.AnnotationAttributes
doGetAnnotationAttributes
(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType) GetAnnotationAttributes
protected final org.springframework.core.annotation.AnnotationAttributes
findInjectionAnnotationAttributes
(AnnotatedElement annotatedElement) final Collection<Class<? extends Annotation>>
final org.springframework.beans.factory.config.ConfigurableListableBeanFactory
final ClassLoader
final org.springframework.core.env.Environment
final int
getOrder()
final void
postProcessMergedBeanDefinition
(org.springframework.beans.factory.support.RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) final org.springframework.beans.PropertyValues
postProcessProperties
(org.springframework.beans.PropertyValues pvs, Object bean, String beanName) final org.springframework.beans.PropertyValues
postProcessPropertyValues
(org.springframework.beans.PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) protected final Object
resolveDependency
(org.springframework.beans.factory.config.DependencyDescriptor desc, String beanName, Set<String> injectedBeanNames) protected Object
resolveInjectedFieldValue
(Object bean, String beanName, org.springframework.beans.PropertyValues pvs, AnnotatedInjectionBeanPostProcessor.AnnotationInjectedElement<Field> fieldElement) Resolve the injected-object as the value of the annotatedField
protected Object[]
resolveInjectedMethodArguments
(Object bean, String beanName, org.springframework.beans.PropertyValues pvs, AnnotatedInjectionBeanPostProcessor.AnnotationInjectedElement<Method> methodElement) Resolve the injected-objects as the arguments of the annotatedmethod
final void
setBeanClassLoader
(ClassLoader classLoader) final void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) final void
setCacheSize
(int cacheSize) Set the size of cachefinal void
setClassValuesAsString
(boolean classValuesAsString) final void
setEnvironment
(org.springframework.core.env.Environment environment) final void
setIgnoreDefaultValue
(boolean ignoreDefaultValue) final void
setNestedAnnotationsAsMap
(boolean nestedAnnotationsAsMap) final void
setOrder
(int order) final void
setTryMergedAnnotation
(boolean tryMergedAnnotation) Methods inherited from class io.microsphere.spring.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
determineBeanType, getEarlyBeanReference, postProcessAfterInitialization, postProcessAfterInstantiation, postProcessBeforeInitialization, postProcessBeforeInstantiation, predictBeanType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization, postProcessBeforeInitialization
Methods inherited from interface org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
resetBeanDefinition
-
Constructor Details
-
AnnotatedInjectionBeanPostProcessor
public AnnotatedInjectionBeanPostProcessor(Class<? extends Annotation> annotationType, Class<? extends Annotation>... otherAnnotationTypes) - Parameters:
annotationType
- the single type ofannotation
-
AnnotatedInjectionBeanPostProcessor
- Parameters:
annotationTypes
- the multiple types ofannotations
-
-
Method Details
-
getAnnotationTypes
-
setBeanFactory
public final 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
-
determineCandidateConstructors
public final Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws org.springframework.beans.BeansException Description copied from class:InstantiationAwareBeanPostProcessorAdapter
- Specified by:
determineCandidateConstructors
in interfaceorg.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
- Overrides:
determineCandidateConstructors
in classInstantiationAwareBeanPostProcessorAdapter
- Throws:
org.springframework.beans.BeansException
-
postProcessPropertyValues
public final org.springframework.beans.PropertyValues postProcessPropertyValues(org.springframework.beans.PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws org.springframework.beans.factory.BeanCreationException Description copied from class:InstantiationAwareBeanPostProcessorAdapter
- Overrides:
postProcessPropertyValues
in classInstantiationAwareBeanPostProcessorAdapter
- Throws:
org.springframework.beans.factory.BeanCreationException
-
postProcessProperties
public final org.springframework.beans.PropertyValues postProcessProperties(org.springframework.beans.PropertyValues pvs, Object bean, String beanName) throws org.springframework.beans.BeansException Description copied from class:InstantiationAwareBeanPostProcessorAdapter
- Specified by:
postProcessProperties
in interfaceorg.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
- Overrides:
postProcessProperties
in classInstantiationAwareBeanPostProcessorAdapter
- Throws:
org.springframework.beans.BeansException
-
determineRequiredStatus
protected boolean determineRequiredStatus(org.springframework.core.annotation.AnnotationAttributes attributes) Determine if the annotated field or method requires its dependency.- Parameters:
attributes
- the injected annotation attributes- Returns:
- whether the annotation indicates that a dependency is required
-
findInjectionAnnotationAttributes
protected final org.springframework.core.annotation.AnnotationAttributes findInjectionAnnotationAttributes(AnnotatedElement annotatedElement) -
doGetAnnotationAttributes
protected final org.springframework.core.annotation.AnnotationAttributes doGetAnnotationAttributes(AnnotatedElement annotatedElement, Class<? extends Annotation> annotationType) GetAnnotationAttributes
- Parameters:
annotatedElement
-the annotated element
annotationType
- thetyoe
pfannotation
- Returns:
- if
annotatedElement
can't be found inannotatedElement
, returnnull
-
postProcessMergedBeanDefinition
public final void postProcessMergedBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) - Specified by:
postProcessMergedBeanDefinition
in interfaceorg.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
-
setClassValuesAsString
public final void setClassValuesAsString(boolean classValuesAsString) - Parameters:
classValuesAsString
- whether to turn Class references into Strings (for compatibility withAnnotationMetadata
or to preserve them as Class references
-
setNestedAnnotationsAsMap
public final void setNestedAnnotationsAsMap(boolean nestedAnnotationsAsMap) - Parameters:
nestedAnnotationsAsMap
- whether to turn nested Annotation instances intoAnnotationAttributes
maps (for compatibility withAnnotationMetadata
or to preserve them as Annotation instances
-
setIgnoreDefaultValue
public final void setIgnoreDefaultValue(boolean ignoreDefaultValue) - Parameters:
ignoreDefaultValue
- whether ignore default value or not
-
setTryMergedAnnotation
public final void setTryMergedAnnotation(boolean tryMergedAnnotation) - Parameters:
tryMergedAnnotation
- whether try merged annotation or not
-
setCacheSize
public final void setCacheSize(int cacheSize) Set the size of cache- Parameters:
cacheSize
- the size of cache
-
setOrder
public final void setOrder(int order) -
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceorg.springframework.beans.factory.BeanClassLoaderAware
-
setEnvironment
public final void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
resolveInjectedFieldValue
protected Object resolveInjectedFieldValue(Object bean, String beanName, org.springframework.beans.PropertyValues pvs, AnnotatedInjectionBeanPostProcessor.AnnotationInjectedElement<Field> fieldElement) throws Throwable Resolve the injected-object as the value of the annotatedField
- Parameters:
bean
- The bean that will be injectedbeanName
- The name of requesting bean that will be injectedpvs
-PropertyValues
fieldElement
-the field element
was annotated- Returns:
- An injected object
- Throws:
Throwable
- If resolving is failed
-
resolveInjectedMethodArguments
protected Object[] resolveInjectedMethodArguments(Object bean, String beanName, org.springframework.beans.PropertyValues pvs, AnnotatedInjectionBeanPostProcessor.AnnotationInjectedElement<Method> methodElement) throws Throwable Resolve the injected-objects as the arguments of the annotatedmethod
- Parameters:
bean
- The bean that will be injectedbeanName
- The name of the bean that will be injectedpvs
-PropertyValues
methodElement
-the method element
was annotated- Returns:
- The array of the injected objects as the arguments of the annotated
method
- Throws:
Throwable
- If resolving is failed
-
resolveDependency
-
getOrder
public final int getOrder()- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
getEnvironment
public final org.springframework.core.env.Environment getEnvironment() -
getClassLoader
-
getBeanFactory
public final org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory()
-