CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework--spring-beans

Spring Beans - IoC Container and Dependency Injection providing comprehensive bean management infrastructure and dependency injection capabilities.

Pending
Overview
Eval results
Files

annotation-config.mddocs/

Annotation-Based Configuration

Comprehensive annotation support for dependency injection, lifecycle callbacks, and bean configuration with automatic detection and processing. This system enables declarative configuration through annotations, reducing the need for XML configuration files.

Capabilities

Core Dependency Injection Annotations

Essential annotations for marking injection points and configuring dependency injection behavior.

/**
 * Marks a constructor, field, setter method, or config method as to be autowired by Spring's dependency injection facilities.
 */
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Autowired {
    /**
     * Declares whether the annotated dependency is required.
     * @return whether the annotated dependency is required
     */
    boolean required() default true;
}

/**
 * This annotation may be used on a field or parameter as a qualifier for candidate beans when autowiring.
 */
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@interface Qualifier {
    /**
     * The qualifier value for the annotated element.
     * @return the qualifier value
     */
    String value() default "";
}

/**
 * Annotation used at the field or method/constructor parameter level that indicates a default value expression for the annotated element.
 */
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Value {
    /**
     * The actual value expression such as "#{systemProperties.myProp}" or property placeholder such as "${my.app.myProp}".
     * @return the value expression
     */
    String value();
}

/**
 * Annotation at the method or type level that indicates that a method should be treated as a factory method.
 */
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Lookup {
    /**
     * This annotation attribute may be used to specify the name of the target bean to look up.
     * @return the name of the target bean to look up
     */
    String value() default "";
}

Bean Configuration Annotations

Annotations for configuring how beans should be created and managed by the Spring container.

/**
 * Marks a class as providing configuration to the container using Spring 2.5's annotation-based container configuration.
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Configurable {
    /**
     * The name of the bean definition that serves as the configuration template.
     * @return the name of the bean definition to use as template
     */
    String value() default "";
    
    /**
     * Are dependencies to be injected via autowiring?
     * @return the autowire mode as defined in the Autowire enum
     */
    Autowire autowire() default Autowire.NO;
    
    /**
     * Is dependency checking to be performed for configured objects?
     * @return whether to apply dependency checking
     */
    boolean dependencyCheck() default false;
    
    /**
     * Are dependencies to be injected prior to the construction of an object?
     * @return whether to apply pre-construction injection
     */
    boolean preConstruction() default false;
}

/**
 * Enumeration used to determine the autowiring strategy.
 */
enum Autowire {
    /** Constant that indicates no autowiring at all. */
    NO(AutowireCapableBeanFactory.AUTOWIRE_NO),
    
    /** Constant that indicates autowiring by name. */
    BY_NAME(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME),
    
    /** Constant that indicates autowiring by type. */
    BY_TYPE(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
    
    private final int value;
    
    Autowire(int value) {
        this.value = value;
    }
    
    /**
     * Return the integer value of this autowiring strategy.
     * @return the integer value
     */
    public int value() {
        return this.value;
    }
    
    /**
     * Return whether this represents an actual autowiring value.
     * @return whether this represents actual autowiring
     */
    public boolean isAutowire() {
        return (this == BY_NAME || this == BY_TYPE);
    }
}

Autowired Annotation Processor

Bean post-processor that processes @Autowired, @Value, and other injection annotations.

/**
 * BeanPostProcessor implementation that autowires annotated fields, setter methods, and arbitrary config methods.
 */
class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, BeanFactoryAware, Ordered {
    /**
     * Create a new AutowiredAnnotationBeanPostProcessor for Spring's standard @Autowired and @Value annotations.
     */
    public AutowiredAnnotationBeanPostProcessor();
    
    /**
     * Set the 'autowired' annotation type, to be used on constructors, fields, setter methods, and arbitrary config methods.
     * @param autowiredAnnotationType the autowired annotation type
     */
    public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType);
    
    /**
     * Set the 'autowired' annotation types, to be used on constructors, fields, setter methods, and arbitrary config methods.
     * @param autowiredAnnotationTypes the autowired annotation types
     */
    public void setAutowiredAnnotationTypes(Set<Class<? extends Annotation>> autowiredAnnotationTypes);
    
    /**
     * Set the name of an attribute of the annotation that specifies whether it is required.
     * @param requiredParameterName the name of the required parameter
     */
    public void setRequiredParameterName(String requiredParameterName);
    
    /**
     * Set the boolean value that marks a dependency as required.
     * @param requiredParameterValue the required parameter value
     */
    public void setRequiredParameterValue(boolean requiredParameterValue);
    
    /**
     * Set the order value of this processor.
     * @param order the order value
     */
    public void setOrder(int order);
    
    /**
     * Return the order value of this processor.
     * @return the order value
     */
    public int getOrder();
    
    /**
     * Set the BeanFactory to use for looking up beans.
     * @param beanFactory the BeanFactory to use
     */
    public void setBeanFactory(BeanFactory beanFactory);
    
    /**
     * Post-process the given merged bean definition for the specified bean.
     * @param beanDefinition the merged bean definition for the bean
     * @param beanType the actual type of the managed bean instance
     * @param beanName the name of the bean
     */
    public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);
    
    /**
     * Reset the cached metadata for the given bean name.
     * @param beanName the name of the bean
     */
    public void resetBeanDefinition(String beanName);
    
    /**
     * Predict the eventual type of the processed bean instance.
     * @param beanClass the raw class of the bean
     * @param beanName the name of the bean
     * @return the type of the bean, or null if not predictable
     */
    public Class<?> predictBeanType(Class<?> beanClass, String beanName);
    
    /**
     * Determine candidate constructors to use for the given bean.
     * @param beanClass the raw class of the bean (never null)
     * @param beanName the name of the bean
     * @return the candidate constructors, or null if none specified
     * @throws BeanCreationException in case of errors
     */
    public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeanCreationException;
    
    /**
     * Post-process the given property values before the factory applies them to the given bean.
     * @param pvs the property values that the factory is about to apply (never null)
     * @param bean the bean instance created, but whose properties have not yet been set
     * @param beanName the name of the bean
     * @return the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or null to skip property population
     * @throws BeansException in case of errors
     */
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException;
}

Qualifier Annotation Support

Support for custom qualifier annotations and qualifier-based autowiring resolution.

/**
 * AutowireCandidateResolver implementation that matches bean definition qualifiers against qualifier annotations on the field or parameter to be autowired.
 */
class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwareAutowireCandidateResolver {
    /** Value annotation type for matching against qualifier values. */
    public static final Class<? extends Annotation> VALUE_ANNOTATION = Value.class;
    
    /**
     * Create a new QualifierAnnotationAutowireCandidateResolver for Spring's standard Qualifier annotation.
     */
    public QualifierAnnotationAutowireCandidateResolver();
    
    /**
     * Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation type.
     * @param qualifierType the qualifier annotation to check for
     */
    public QualifierAnnotationAutowireCandidateResolver(Class<? extends Annotation> qualifierType);
    
    /**
     * Create a new QualifierAnnotationAutowireCandidateResolver for the given qualifier annotation types.
     * @param qualifierTypes the qualifier annotations to check for
     */
    public QualifierAnnotationAutowireCandidateResolver(Set<Class<? extends Annotation>> qualifierTypes);
    
    /**
     * Register an additional qualifier annotation type.
     * @param qualifierType the qualifier annotation to check for
     */
    public void addQualifierType(Class<? extends Annotation> qualifierType);
    
    /**
     * Set the 'value' annotation type, to be used on fields, setter methods, and parameters as a qualifiying hint.
     * @param valueAnnotationType the value annotation type
     */
    public void setValueAnnotationType(Class<? extends Annotation> valueAnnotationType);
    
    /**
     * Determine whether the provided bean definition is an autowire candidate.
     * @param bdHolder the bean definition including bean name and aliases
     * @param descriptor the descriptor for the target method parameter or field
     * @return whether the bean definition qualifies as autowire candidate
     */
    public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor);
    
    /**
     * Determine whether the given dependency declares a required annotation.
     * @param descriptor the descriptor for the target method parameter or field
     * @return whether the dependency declares a required annotation
     */
    public boolean isRequired(DependencyDescriptor descriptor);
    
    /**
     * Determine whether the given dependency declares a qualifier annotation.
     * @param descriptor the descriptor for the target method parameter or field
     * @return whether the dependency declares a qualifier annotation
     */
    public boolean hasQualifier(DependencyDescriptor descriptor);
    
    /**
     * Determine a suggested name for the given dependency.
     * @param descriptor the descriptor for the target method parameter or field
     * @return a suggested name (may be null if none found)
     */
    public String getSuggestedName(DependencyDescriptor descriptor);
    
    /**
     * Determine a suggested value for the given dependency.
     * @param descriptor the descriptor for the target method parameter or field
     * @return a suggested value (may be null if none found)
     */
    public Object getSuggestedValue(DependencyDescriptor descriptor);
}

Injection Metadata Support

Infrastructure for managing and processing injection points discovered through annotation scanning.

/**
 * Internal class for managing injection metadata.
 */
class InjectionMetadata {
    /** Empty metadata instance shared for efficiency. */
    public static final InjectionMetadata EMPTY = new InjectionMetadata(Object.class, Collections.emptyList());
    
    /**
     * Create a new InjectionMetadata instance.
     * @param targetClass the target class
     * @param elements the associated elements to inject
     */
    public InjectionMetadata(Class<?> targetClass, Collection<InjectedElement> elements);
    
    /**
     * Determine if this metadata instance has any injection elements.
     * @return whether this metadata instance has any injection elements
     */
    public boolean needsRefresh();
    
    /**
     * Mark the specified elements as externally managed configuration members.
     * @param beanDefinition the bean definition to mark up
     */
    public void checkConfigMembers(RootBeanDefinition beanDefinition);
    
    /**
     * Inject the configured resources into the given target bean.
     * @param target the target bean
     * @param beanName the name of the target bean
     * @param pvs the property values (can be null)
     * @throws Throwable if injection failed
     */
    public void inject(Object target, String beanName, PropertyValues pvs) throws Throwable;
    
    /**
     * Clear property skipping for the contained elements.
     * @param pvs the property values (can be null)
     */
    public void clear(PropertyValues pvs);
    
    /**
     * Return all InjectedElements held by this metadata instance.
     * @return the injected elements (possibly empty, but never null)
     */
    public Collection<InjectedElement> getInjectedElements();
    
    /**
     * Return all InjectedElements held by this metadata instance that are not present as property values.
     * @param pvs the property values (can be null)
     * @return the injected elements (possibly empty, but never null)
     */
    public Collection<InjectedElement> getInjectedElements(PropertyValues pvs);
    
    /**
     * Build an InjectionMetadata instance from the given target class and element collection.
     * @param elements the elements to include
     * @param clazz the target class
     * @return the injection metadata instance
     */
    public static InjectionMetadata forElements(Collection<InjectedElement> elements, Class<?> clazz);
    
    /**
     * Check whether the given injection metadata needs to be refreshed.
     * @param metadata the existing metadata instance
     * @param clazz the current target class
     * @return whether a refresh is needed
     */
    public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz);
    
    /**
     * A single injected element.
     */
    public abstract static class InjectedElement {
        protected final Member member;
        protected final boolean isField;
        protected final PropertyDescriptor pd;
        protected volatile Boolean skip;
        
        /**
         * Create a new InjectedElement.
         * @param member the member to inject into
         * @param pd the corresponding property descriptor, if any
         */
        protected InjectedElement(Member member, PropertyDescriptor pd);
        
        /**
         * Return the member to inject into.
         * @return the member
         */
        public final Member getMember();
        
        /**
         * Return the class that declares the member to inject into.
         * @return the declaring class
         */
        protected final Class<?> getResourceType();
        
        /**
         * Check whether this element is externally managed.
         * @param beanDefinition the bean definition to check against
         */
        protected void checkResourceType(RootBeanDefinition beanDefinition);
        
        /**
         * Either this or inject() needs to be overridden.
         * @param target the target instance
         * @param requestingBeanName the name of the requesting bean
         * @param pvs the property values
         * @throws Throwable if injection failed
         */
        protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable;
        
        /**
         * Clear the property skipping marker, if any.
         * @param pvs the property values
         */
        protected void clearPropertySkipping(PropertyValues pvs);
    }
}

Bean Wiring Info Resolution

Support for resolving wiring information for beans, particularly useful for aspect-driven dependency injection.

/**
 * Strategy interface to be implemented by objects that can resolve bean wiring information for a bean instance.
 */
interface BeanWiringInfoResolver {
    /**
     * Resolve the BeanWiringInfo for the given bean instance.
     * @param beanInstance the bean instance to resolve info for
     * @return the BeanWiringInfo for the given bean, or null if no information found
     */
    BeanWiringInfo resolveWiringInfo(Object beanInstance);
}

/**
 * Simple default implementation of the BeanWiringInfoResolver interface, looking for a bean with the same name as the fully-qualified class name.
 */
class ClassNameBeanWiringInfoResolver implements BeanWiringInfoResolver {
    /**
     * Resolve the BeanWiringInfo for the given bean instance.
     * @param beanInstance the bean instance to resolve info for
     * @return the BeanWiringInfo for the given bean
     */
    public BeanWiringInfo resolveWiringInfo(Object beanInstance);
}

/**
 * BeanWiringInfoResolver that uses the Configurable annotation to identify which classes need autowiring.
 */
class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver {
    /**
     * Resolve the BeanWiringInfo for the given bean instance.
     * @param beanInstance the bean instance to resolve info for
     * @return the BeanWiringInfo for the given bean, or null if the bean isn't configured for autowiring
     */
    public BeanWiringInfo resolveWiringInfo(Object beanInstance);
}

Usage Examples:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;

// Basic dependency injection
public class OrderService {
    
    @Autowired
    private PaymentService paymentService;
    
    @Autowired
    private OrderRepository orderRepository;
    
    @Value("${order.timeout:30}")
    private int timeout;
    
    // Constructor injection (recommended)
    @Autowired
    public OrderService(PaymentService paymentService, OrderRepository orderRepository) {
        this.paymentService = paymentService;
        this.orderRepository = orderRepository;
    }
    
    // Setter injection
    @Autowired
    public void setPaymentService(PaymentService paymentService) {
        this.paymentService = paymentService;
    }
    
    // Method injection with multiple parameters
    @Autowired
    public void configure(PaymentService paymentService, 
                         @Qualifier("primary") OrderRepository orderRepository,
                         @Value("${order.max-retries:3}") int maxRetries) {
        this.paymentService = paymentService;
        this.orderRepository = orderRepository;
        this.maxRetries = maxRetries;
    }
}

// Qualifier usage
public class PaymentServiceConfiguration {
    
    @Autowired
    @Qualifier("creditCard")
    private PaymentProcessor creditCardProcessor;
    
    @Autowired
    @Qualifier("paypal")  
    private PaymentProcessor paypalProcessor;
    
    // Collection injection with qualifiers
    @Autowired
    @Qualifier("highPriority")
    private List<NotificationService> highPriorityServices;
    
    // Map injection with qualifiers  
    @Autowired
    private Map<String, PaymentProcessor> paymentProcessors;
}

// Optional dependencies
public class OptionalDependencyExample {
    
    @Autowired(required = false)
    private Optional<CacheService> cacheService;
    
    @Autowired(required = false)
    private List<Plugin> plugins = new ArrayList<>();
    
    public void doSomething() {
        cacheService.ifPresent(cache -> cache.put("key", "value"));
        plugins.forEach(Plugin::execute);
    }
}

// Configuration with @Configurable for domain objects
@Configurable(preConstruction = true)
public class Order {
    
    @Autowired
    private AuditService auditService;
    
    @Value("${order.default.currency:USD}")
    private String defaultCurrency;
    
    public Order() {
        // Dependencies are injected before constructor completes
        auditService.logOrderCreation(this);
    }
}

// Custom qualifiers
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface PaymentMethod {
    String value() default "";
}

public class PaymentController {
    
    @Autowired
    @PaymentMethod("creditCard")
    private PaymentProcessor processor;
}

Lifecycle Annotation Support

Support for JSR-250 lifecycle annotations and custom lifecycle annotation processing.

/**
 * BeanPostProcessor implementation that supports common Java annotations out of the box.
 */
class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, BeanFactoryAware, Ordered {
    /**
     * Create a new InitDestroyAnnotationBeanPostProcessor instance.
     */
    public InitDestroyAnnotationBeanPostProcessor();
    
    /**
     * Specify the init annotation to check for, indicating initialization methods to call after configuration of a bean.
     * @param initAnnotationType the init annotation type
     */
    public void setInitAnnotationType(Class<? extends Annotation> initAnnotationType);
    
    /**
     * Add an init annotation to check for, indicating initialization methods to call after configuration of a bean.
     * @param initAnnotationType the init annotation type to add
     */
    public void addInitAnnotationType(Class<? extends Annotation> initAnnotationType);
    
    /**
     * Specify the destroy annotation to check for, indicating destruction methods to call when the context is shutting down.
     * @param destroyAnnotationType the destroy annotation type
     */
    public void setDestroyAnnotationType(Class<? extends Annotation> destroyAnnotationType);
    
    /**
     * Add a destroy annotation to check for, indicating destruction methods to call when the context is shutting down.
     * @param destroyAnnotationType the destroy annotation type to add
     */
    public void addDestroyAnnotationType(Class<? extends Annotation> destroyAnnotationType);
    
    /**
     * Set the order value of this processor.
     * @param order the order value
     */
    public void setOrder(int order);
    
    /**
     * Return the order value of this processor.
     * @return the order value
     */
    public int getOrder();
    
    /**
     * Set the BeanFactory to use for looking up beans.
     * @param beanFactory the BeanFactory to use
     */
    public void setBeanFactory(BeanFactory beanFactory);
    
    /**
     * Post-process the given merged bean definition for the specified bean.
     * @param beanDefinition the merged bean definition for the bean
     * @param beanType the actual type of the managed bean instance
     * @param beanName the name of the bean
     */
    public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);
    
    /**
     * Reset the cached metadata for the given bean name.
     * @param beanName the name of the bean
     */
    public void resetBeanDefinition(String beanName);
    
    /**
     * Check whether the given bean definition specifies any initialization methods.
     * @param beanDefinition the bean definition to check
     */
    public void checkInitDestroyMethods(RootBeanDefinition beanDefinition);
    
    /**
     * Invoke the initialization methods on the given bean instance.
     * @param target the target bean instance
     * @param beanName the name of the bean
     * @throws Throwable if initialization failed
     */
    public void invokeInitMethods(Object target, String beanName) throws Throwable;
    
    /**
     * Invoke the destruction methods on the given bean instance.
     * @param target the target bean instance  
     * @param beanName the name of the bean
     * @throws Throwable if destruction failed
     */
    public void invokeDestroyMethods(Object target, String beanName) throws Throwable;
    
    /**
     * Determine whether the given bean has any destroy methods.
     * @return whether the bean has destroy methods
     */
    public boolean hasDestroyMethods();
}

Additional Dependency Injection Annotations

Extended annotation support for specialized injection scenarios and method-based dependencies.

/**
 * Annotation to be used on methods in a Spring application context for method injection scenarios.
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Lookup {
    /**
     * This attribute may suggest a target bean name to look up.
     * @return the suggested target bean name, if any (or empty String if none)
     */
    String value() default "";
}

/**
 * Marks a method as being 'required' - that is, it must be configured to be dependency-injected with a value.
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@interface Required {
}

Bean Post-Processor Implementations

Concrete implementations of bean post-processors for handling annotations and injection.

/**
 * BeanPostProcessor implementation that processes @Autowired, @Value, and @Inject annotations.
 */
class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware {
    /** The default autowired annotation types. */
    public static final Set<Class<? extends Annotation>> AUTOWIRED_ANNOTATION_TYPES;
    
    /**
     * Create a new AutowiredAnnotationBeanPostProcessor for Spring's @Autowired and @Value annotations.
     */
    public AutowiredAnnotationBeanPostProcessor();
    
    /**
     * Set the 'autowired' annotation type, to be used on constructors, fields, setter methods, and arbitrary config methods.
     * @param autowiredAnnotationType the annotation type to check for
     */
    public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType);
    
    /**
     * Set the 'autowired' annotation types, to be used on constructors, fields, setter methods, and arbitrary config methods.
     * @param autowiredAnnotationTypes the annotation types to check for
     */
    public void setAutowiredAnnotationTypes(Set<Class<? extends Annotation>> autowiredAnnotationTypes);
    
    /**
     * Set the name of an attribute of the annotation that specifies whether it is required.
     * @param requiredParameterName the name of the required attribute
     */
    public void setRequiredParameterName(String requiredParameterName);
    
    /**
     * Set the value of the annotation attribute that specifies that a dependency is required.
     * @param requiredParameterValue the required attribute value
     */
    public void setRequiredParameterValue(boolean requiredParameterValue);
    
    /**
     * Set the order value of this object.
     * @param order the order value
     */
    public void setOrder(int order);
    
    /**
     * Return the order value of this object.
     * @return the order value
     */
    public int getOrder();
    
    /**
     * Set the BeanFactory to be used by this processor.
     * @param beanFactory the BeanFactory
     */
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException;
    
    /**
     * This implementation processes @Autowired, @Value, and JSR-330 @Inject annotations.
     * @param beanDefinition the merged bean definition for the bean
     * @param beanType the actual type of the managed bean instance
     * @param beanName the name of the bean
     */
    public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);
    
    /**
     * This implementation resets the injection metadata if the bean definition changes.
     * @param beanName the name of the bean
     */
    public void resetBeanDefinition(String beanName);
    
    /**
     * This implementation returns candidate constructors.
     * @param beanClass the raw class of the bean
     * @param beanName the name of the bean
     * @return the candidate constructors, or null if none
     * @throws BeansException in case of errors
     */
    public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException;
    
    /**
     * This implementation processes @Autowired, @Value, and @Inject annotations.
     * @param pvs the property values that the factory is about to apply (never null)
     * @param bean the bean instance created, but whose properties have not yet been set
     * @param beanName the name of the bean
     * @return the actual property values to apply to the given bean
     * @throws BeansException in case of errors
     */
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException;
    
    /**
     * This implementation processes @Autowired annotations, checking whether the annotation is present on this post-processor's 'required' annotation list.
     * @param pvs the property values that the factory is about to apply (never null)
     * @param pds the relevant property descriptors for the target bean
     * @param bean the bean instance created, but whose properties have not yet been set
     * @param beanName the name of the bean
     * @return the actual property values to apply to the given bean
     * @throws BeansException in case of errors
     * @deprecated as of 5.1, in favor of postProcessProperties
     */
    @Deprecated
    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException;
}

/**
 * Simple processor for JSR-250 style annotations: @PostConstruct, @PreDestroy, and @Resource.
 */
class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBeanPostProcessor implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable {
    /**
     * Create a new CommonAnnotationBeanPostProcessor.
     */
    public CommonAnnotationBeanPostProcessor();
    
    /**
     * Set the 'init' annotation type, to be used on lifecycle methods.
     * @param initAnnotationType the annotation type to check for
     */
    public void setInitAnnotationType(Class<? extends Annotation> initAnnotationType);
    
    /**
     * Set the 'destroy' annotation type, to be used on lifecycle methods.
     * @param destroyAnnotationType the annotation type to check for
     */
    public void setDestroyAnnotationType(Class<? extends Annotation> destroyAnnotationType);
    
    /**
     * Ignore the given resource type when resolving @Resource annotations.
     * @param resourceType the resource type to ignore
     */
    public void ignoreResourceType(String resourceType);
    
    /**
     * Set the BeanFactory to be used by this processor.
     * @param beanFactory the BeanFactory
     */
    public void setBeanFactory(BeanFactory beanFactory);
    
    /**
     * This implementation processes @Resource annotations.
     * @param pvs the property values that the factory is about to apply (never null)
     * @param bean the bean instance created, but whose properties have not yet been set
     * @param beanName the name of the bean
     * @return the actual property values to apply to the given bean
     * @throws BeansException in case of errors
     */
    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException;
    
    /**
     * This implementation processes @Resource annotations.
     * @param pvs the property values that the factory is about to apply (never null)
     * @param pds the relevant property descriptors for the target bean
     * @param bean the bean instance created, but whose properties have not yet been set
     * @param beanName the name of the bean
     * @return the actual property values to apply to the given bean
     * @throws BeansException in case of errors
     * @deprecated as of 5.1, in favor of postProcessProperties
     */
    @Deprecated
    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException;
}

/**
 * Simple processor for methods annotated with @Required.
 */
class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter implements MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware {
    /**
     * Bean post processor marker that indicates whether a bean's required properties have been checked.
     */
    public static final String SKIP_REQUIRED_CHECK_ATTRIBUTE = RequiredAnnotationBeanPostProcessor.class.getName() + ".SKIP_REQUIRED_CHECK_ATTRIBUTE";
    
    /**
     * Create a new RequiredAnnotationBeanPostProcessor.
     */
    public RequiredAnnotationBeanPostProcessor();
    
    /**
     * Set the 'required' annotation type, to be used on bean property setter methods.
     * @param requiredAnnotationType the annotation type to check for
     */
    public void setRequiredAnnotationType(Class<? extends Annotation> requiredAnnotationType);
    
    /**
     * Return the 'required' annotation type.
     * @return the 'required' annotation type
     */
    protected Class<? extends Annotation> getRequiredAnnotationType();
    
    /**
     * Set the order value of this object.
     * @param order the order value
     */
    public void setOrder(int order);
    
    /**
     * Return the order value of this object.
     * @return the order value
     */
    public int getOrder();
    
    /**
     * Set the BeanFactory to be used by this processor.
     * @param beanFactory the BeanFactory
     */
    public void setBeanFactory(BeanFactory beanFactory);
    
    /**
     * This implementation processes @Required annotations.
     * @param beanDefinition the merged bean definition for the bean
     * @param beanType the actual type of the managed bean instance
     * @param beanName the name of the bean
     */
    public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);
    
    /**
     * This implementation checks for @Required annotations.
     * @param pvs the property values that the factory is about to apply (never null)
     * @param pds the relevant property descriptors for the target bean
     * @param bean the bean instance created, but whose properties have not yet been set
     * @param beanName the name of the bean
     * @return the actual property values to apply to the given bean (can be the passed-in PropertyValues instance)
     * @throws BeansException in case of errors
     * @deprecated as of 5.1, in favor of postProcessProperties
     */
    @Deprecated
    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException;
}

Injection Metadata Support

Classes that manage metadata about injection points and provide runtime injection support.

/**
 * Internal class for managing injection metadata.
 */
class InjectionMetadata {
    /**
     * An empty InjectionMetadata instance with no-op callbacks.
     */
    public static final InjectionMetadata EMPTY = new InjectionMetadata(Object.class, Collections.emptyList());
    
    /**
     * Create a new InjectionMetadata instance.
     * @param targetClass the target class
     * @param injectedElements the (typically field and method) elements to inject
     */
    public InjectionMetadata(Class<?> targetClass, Collection<InjectedElement> injectedElements);
    
    /**
     * Create a new InjectionMetadata instance.
     * @param targetClass the target class
     * @param injectedElements the (typically field and method) elements to inject
     */
    public InjectionMetadata(Class<?> targetClass, InjectedElement... injectedElements);
    
    /**
     * Check configuration of this metadata.
     * @param beanName the name of the bean
     */
    public void checkConfigMembers(RootBeanDefinition beanDefinition);
    
    /**
     * Inject the configured elements into the given target bean.
     * @param target the target bean
     * @param beanName the name of the bean
     * @param pvs the PropertyValues for the bean (may be null)
     * @throws Throwable if injection failed
     */
    public void inject(Object target, String beanName, PropertyValues pvs) throws Throwable;
    
    /**
     * Clear property skipping for the contained elements.
     */
    public void clear(PropertyValues pvs);
    
    /**
     * Check whether this injector has determined that it needs to skip the bean property with the given name.
     * @param pvs the PropertyValues to check
     * @param pd the PropertyDescriptor of the target property
     * @return whether this injector suggests skipping the property
     */
    public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz);
    
    /**
     * A single injected element.
     */
    public abstract static class InjectedElement {
        /**
         * Create a new InjectedElement for the given member.
         * @param member the member
         * @param pd the PropertyDescriptor, if any
         */
        protected InjectedElement(Member member, PropertyDescriptor pd);
        
        /**
         * Return the annotation metadata.
         * @return the annotation metadata
         */
        public final Member getMember();
        
        /**
         * Return the related PropertyDescriptor if any.
         * @return the PropertyDescriptor, or null if none
         */
        protected final PropertyDescriptor getPropertyDescriptor();
        
        /**
         * Check whether this injector has determined that it needs to skip the bean property with the given name.
         * @param pvs the PropertyValues to check
         * @return whether this injector suggests skipping the property
         */
        public boolean isSkipped(PropertyValues pvs);
        
        /**
         * Either this or {inject} needs to be overridden.
         * @param target the target bean
         * @param beanName the name of the bean
         * @param pvs the PropertyValues for the bean
         * @throws Throwable if injection failed
         */
        protected void inject(Object target, String beanName, PropertyValues pvs) throws Throwable;
        
        /**
         * Either this or {inject} needs to be overridden.
         * @param beanDefinition the bean definition to check
         */
        protected void checkResourceType(RootBeanDefinition beanDefinition);
    }
}

/**
 * Descriptor for a specific dependency that is about to be injected.
 */
class DependencyDescriptor implements Serializable {
    /**
     * Create a new descriptor for a field.
     * @param field the field to wrap
     * @param required whether the dependency is required
     */
    public DependencyDescriptor(Field field, boolean required);
    
    /**
     * Create a new descriptor for a field.
     * @param field the field to wrap
     * @param required whether the dependency is required
     * @param eager whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching
     */
    public DependencyDescriptor(Field field, boolean required, boolean eager);
    
    /**
     * Create a new descriptor for a method or constructor parameter.
     * @param methodParameter the MethodParameter to wrap
     * @param required whether the dependency is required
     */
    public DependencyDescriptor(MethodParameter methodParameter, boolean required);
    
    /**
     * Create a new descriptor for a method or constructor parameter.
     * @param methodParameter the MethodParameter to wrap
     * @param required whether the dependency is required
     * @param eager whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching
     */
    public DependencyDescriptor(MethodParameter methodParameter, boolean required, boolean eager);
    
    /**
     * Copy constructor.
     * @param original the original descriptor to copy from
     */
    public DependencyDescriptor(DependencyDescriptor original);
    
    /**
     * Return whether this dependency is required.
     * @return whether this dependency is required
     */
    public boolean isRequired();
    
    /**
     * Return whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching.
     * @return whether this dependency is eager
     */
    public boolean isEager();
    
    /**
     * Resolve the specified not-unique scenario: by default, throwing a NoUniqueBeanDefinitionException.
     * @param type the requested bean type
     * @param matchingBeans a map of bean names and corresponding bean instances which have been pre-selected for the given type
     * @return a candidate bean name to proceed with
     * @throws BeansException in case of the not-unique scenario being fatal
     */
    public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) throws BeansException;
    
    /**
     * Resolve a shortcut for this dependency against the given factory.
     * @param beanFactory the BeanFactory to resolve against
     * @return the shortcut result if any, or null if none
     * @throws BeansException if the shortcut could not be obtained
     */
    public Object resolveShortcut(AutowireCapableBeanFactory beanFactory) throws BeansException;
    
    /**
     * Resolve this dependency against the given factory.
     * @param beanFactory the BeanFactory to resolve against
     * @return the resolved object, or null if not found
     * @throws BeansException if the dependency could not be resolved
     */
    public Object resolveCandidate(String beanName, Class<?> requiredType, BeanFactory beanFactory) throws BeansException;
    
    /**
     * Return the wrapped MethodParameter, if any.
     * @return the MethodParameter, or null if none
     */
    public MethodParameter getMethodParameter();
    
    /**
     * Return the wrapped Field, if any.
     * @return the Field, or null if none
     */
    public Field getField();
    
    /**
     * Return whether a fallback match is allowed.
     * @return whether a fallback match is allowed
     */
    public boolean fallbackMatchAllowed();
    
    /**
     * Return a variant of this descriptor that is intended for a fallback match.
     * @return the fallback descriptor (never null)
     */
    public DependencyDescriptor forFallbackMatch();
    
    /**
     * Initialize parameter name discovery for the underlying method parameter, if any.
     */
    public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer);
    
    /**
     * Determine the name of the wrapped parameter/field.
     * @return the declared name (may be null if unresolvable)
     */
    public String getDependencyName();
    
    /**
     * Determine the declared (non-generic) type of the wrapped parameter/field.
     * @return the declared type (never null)
     */
    public Class<?> getDependencyType();
    
    /**
     * Determine the generic type of the wrapped parameter/field.
     * @return the generic type (never null)
     */
    public ResolvableType getResolvableType();
    
    /**
     * Return whether the wrapped parameter/field expects a collection of elements.
     * @return whether a collection is expected
     */
    public boolean isCollectionType();
    
    /**
     * Return whether the wrapped parameter/field expects an array of elements.
     * @return whether an array is expected
     */
    public boolean isArrayType();
    
    /**
     * Return whether the wrapped parameter/field expects a map of elements.
     * @return whether a map is expected
     */
    public boolean isMapType();
    
    /**
     * Return whether the wrapped parameter/field expects an optional dependency.
     * @return whether an optional dependency is expected
     */
    public boolean isOptional();
}

Install with Tessl CLI

npx tessl i tessl/maven-org-springframework--spring-beans

docs

annotation-config.md

aot-support.md

bean-definition.md

bean-factory.md

index.md

property-access.md

xml-config.md

tile.json