Class 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
    • Field Summary

      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      AnnotatedInjectionBeanPostProcessor​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.Class<? extends java.lang.annotation.Annotation>... otherAnnotationTypes)  
      AnnotatedInjectionBeanPostProcessor​(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)  
    • Constructor Detail

      • AnnotatedInjectionBeanPostProcessor

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

        public AnnotatedInjectionBeanPostProcessor​(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> annotationTypes)
        Parameters:
        annotationTypes - the multiple types of annotations
    • Method Detail

      • getAnnotationTypes

        public final java.util.Collection<java.lang.Class<? extends java.lang.annotation.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 java.lang.reflect.Constructor<?>[] determineCandidateConstructors​(java.lang.Class<?> beanClass,
                                                                                       java.lang.String beanName)
                                                                                throws org.springframework.beans.BeansException
        Description copied from class: InstantiationAwareBeanPostProcessorAdapter
        Determine the candidate constructors to use for the given bean.

        The default implementation returns null.

        Specified by:
        determineCandidateConstructors in interface org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
        Overrides:
        determineCandidateConstructors in class InstantiationAwareBeanPostProcessorAdapter
        Parameters:
        beanClass - the raw class of the bean (never null)
        beanName - the name of the bean
        Returns:
        the candidate constructors, or null if none specified
        Throws:
        org.springframework.beans.BeansException - in case of errors
      • postProcessPropertyValues

        public final org.springframework.beans.PropertyValues postProcessPropertyValues​(org.springframework.beans.PropertyValues pvs,
                                                                                        java.beans.PropertyDescriptor[] pds,
                                                                                        java.lang.Object bean,
                                                                                        java.lang.String beanName)
                                                                                 throws org.springframework.beans.factory.BeanCreationException
        Description copied from class: InstantiationAwareBeanPostProcessorAdapter
        Post-process the given property values before the factory applies them to the given bean. Allows for checking whether all dependencies have been satisfied, for example based on a "Required" annotation on bean property setters.

        Also allows for replacing the property values to apply, typically through creating a new MutablePropertyValues instance based on the original PropertyValues, adding or removing specific values.

        The default implementation returns the given pvs as-is.

        Specified by:
        postProcessPropertyValues in interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
        Overrides:
        postProcessPropertyValues in class InstantiationAwareBeanPostProcessorAdapter
        Parameters:
        pvs - the property values that the factory is about to apply (never null)
        pds - the relevant property descriptors for the target bean (with ignored dependency types - which the factory handles specifically - already filtered out)
        bean - the bean instance created, but whose properties have not yet been set
        beanName - the name of the bean
        Returns:
        the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or null to skip property population
        Throws:
        org.springframework.beans.factory.BeanCreationException
        See Also:
        InstantiationAwareBeanPostProcessorAdapter.postProcessProperties(org.springframework.beans.PropertyValues, java.lang.Object, java.lang.String), MutablePropertyValues
      • postProcessProperties

        public final org.springframework.beans.PropertyValues postProcessProperties​(org.springframework.beans.PropertyValues pvs,
                                                                                    java.lang.Object bean,
                                                                                    java.lang.String beanName)
                                                                             throws org.springframework.beans.BeansException
        Description copied from class: InstantiationAwareBeanPostProcessorAdapter
        Post-process the given property values before the factory applies them to the given bean.

        The default implementation returns the given pvs as-is.

        Specified by:
        postProcessProperties in interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
        Overrides:
        postProcessProperties in class InstantiationAwareBeanPostProcessorAdapter
        Parameters:
        pvs - the property values that the factory is about to apply (never null)
        bean - the bean instance created, but whose properties have not yet been set
        beanName - the name of the bean
        Returns:
        the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or null to skip property population
        Throws:
        org.springframework.beans.BeansException - in case of errors
      • 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​(java.lang.reflect.AnnotatedElement annotatedElement)
      • doGetAnnotationAttributes

        protected final org.springframework.core.annotation.AnnotationAttributes doGetAnnotationAttributes​(java.lang.reflect.AnnotatedElement annotatedElement,
                                                                                                           java.lang.Class<? extends java.lang.annotation.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,
                                                          java.lang.Class<?> beanType,
                                                          java.lang.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​(java.lang.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 java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • destroy

        public void destroy()
                     throws java.lang.Exception
        Specified by:
        destroy in interface org.springframework.beans.factory.DisposableBean
        Throws:
        java.lang.Exception
      • resolveInjectedFieldValue

        protected java.lang.Object resolveInjectedFieldValue​(java.lang.Object bean,
                                                             java.lang.String beanName,
                                                             org.springframework.beans.PropertyValues pvs,
                                                             AnnotatedInjectionBeanPostProcessor.AnnotationInjectedElement<java.lang.reflect.Field> fieldElement)
                                                      throws java.lang.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:
        java.lang.Throwable - If resolving is failed
      • resolveInjectedMethodArguments

        protected java.lang.Object[] resolveInjectedMethodArguments​(java.lang.Object bean,
                                                                    java.lang.String beanName,
                                                                    org.springframework.beans.PropertyValues pvs,
                                                                    AnnotatedInjectionBeanPostProcessor.AnnotationInjectedElement<java.lang.reflect.Method> methodElement)
                                                             throws java.lang.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:
        java.lang.Throwable - If resolving is failed
      • resolveDependency

        protected final java.lang.Object resolveDependency​(org.springframework.beans.factory.config.DependencyDescriptor desc,
                                                           java.lang.String beanName,
                                                           java.util.Set<java.lang.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 java.lang.ClassLoader getClassLoader()
      • getBeanFactory

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