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:

Since:
1.0.0
Author:
Mercy
See Also:
  • AutowiredAnnotationBeanPostProcessor
  • Constructor Details

    • AnnotatedInjectionBeanPostProcessor

      public AnnotatedInjectionBeanPostProcessor(Class<? extends Annotation> annotationType, Class<? extends Annotation>... otherAnnotationTypes)
      Parameters:
      annotationType - the single type of annotation
    • AnnotatedInjectionBeanPostProcessor

      public AnnotatedInjectionBeanPostProcessor(Collection<Class<? extends Annotation>> annotationTypes)
      Parameters:
      annotationTypes - the multiple types of annotations
  • Method Details

    • getAnnotationTypes

      public final Collection<Class<? extends Annotation>> getAnnotationTypes()
    • setBeanFactory

      public final void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.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 interface org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
      Overrides:
      determineCandidateConstructors in class InstantiationAwareBeanPostProcessorAdapter
      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 class InstantiationAwareBeanPostProcessorAdapter
      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 interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
      Overrides:
      postProcessProperties in class InstantiationAwareBeanPostProcessorAdapter
      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)
      Get AnnotationAttributes
      Parameters:
      annotatedElement - the annotated element
      annotationType - the tyoe pf annotation
      Returns:
      if annotatedElement can't be found in annotatedElement, return null
    • postProcessMergedBeanDefinition

      public final void postProcessMergedBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition beanDefinition, Class<?> beanType, String beanName)
      Specified by:
      postProcessMergedBeanDefinition in interface org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
    • setClassValuesAsString

      public final void setClassValuesAsString(boolean classValuesAsString)
      Parameters:
      classValuesAsString - whether to turn Class references into Strings (for compatibility with AnnotationMetadata or to preserve them as Class references
    • setNestedAnnotationsAsMap

      public final void setNestedAnnotationsAsMap(boolean nestedAnnotationsAsMap)
      Parameters:
      nestedAnnotationsAsMap - whether to turn nested Annotation instances into AnnotationAttributes maps (for compatibility with AnnotationMetadata 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

      public final void setBeanClassLoader(ClassLoader classLoader)
      Specified by:
      setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAware
    • setEnvironment

      public final void setEnvironment(org.springframework.core.env.Environment environment)
      Specified by:
      setEnvironment in interface org.springframework.context.EnvironmentAware
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.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 annotated Field
      Parameters:
      bean - The bean that will be injected
      beanName - The name of requesting bean that will be injected
      pvs - 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 annotated method
      Parameters:
      bean - The bean that will be injected
      beanName - The name of the bean that will be injected
      pvs - 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

      protected final Object resolveDependency(org.springframework.beans.factory.config.DependencyDescriptor desc, String beanName, Set<String> injectedBeanNames)
    • getOrder

      public final int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
    • getEnvironment

      public final org.springframework.core.env.Environment getEnvironment()
    • getClassLoader

      public final ClassLoader getClassLoader()
    • getBeanFactory

      public final org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory()