Top Description Fields Constructors Methods
org.springframework.beans.factory.annotation

public final Class ParameterResolutionDelegate

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.AnnotatedElement, .Constructor, .Executable, .Parameter, org.springframework.beans.BeansException, org.springframework.beans.factory.config.AutowireCapableBeanFactory, .DependencyDescriptor, org.springframework.core.MethodParameter, org.springframework.core.annotation.AnnotatedElementUtils, .SynthesizingMethodParameter, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils

Public delegate for resolving autowirable parameters on externally managed constructors and methods.
Authors
Sam Brannen, Juergen Hoeller
Since
5.2
See Also
isAutowirable, resolveDependency

Field Summary

Modifier and TypeField and Description
private static final AnnotatedElement

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static AnnotatedElement

Returns:

the supplied parameter or the effective Parameter if the aforementioned bug is in effect
getEffectiveAnnotatedParameter
(Parameter parameter, int index)

Due to a bug in javac on JDK versions prior to JDK 9, looking up annotations directly on a Parameter will fail for inner class constructors.

public static boolean
isAutowirable(Parameter
the parameter whose dependency should be autowired (must not be null)
parameter
,
int
the index of the parameter in the constructor or method that declares the parameter
parameterIndex
)

Determine if the supplied Parameter can potentially be autowired from an AutowireCapableBeanFactory.

public static Object

Returns:

the resolved object, or null if none found
resolveDependency
(Parameter
the parameter whose dependency should be resolved (must not be null)
parameter
,
int
the index of the parameter in the constructor or method that declares the parameter
parameterIndex
,
Class<?>
the concrete class that contains the parameter; this may differ from the class that declares the parameter in that it may be a subclass thereof, potentially substituting type variables (must not be null)
containingClass
,
AutowireCapableBeanFactory
the AutowireCapableBeanFactory from which to resolve the dependency (must not be null)
beanFactory
)

Resolve the dependency for the supplied Parameter from the supplied AutowireCapableBeanFactory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_ANNOTATED_ELEMENTback to summary
private static final AnnotatedElement EMPTY_ANNOTATED_ELEMENT

Constructor Detail

ParameterResolutionDelegateback to summary
private ParameterResolutionDelegate()

Method Detail

getEffectiveAnnotatedParameterback to summary
private static AnnotatedElement getEffectiveAnnotatedParameter(Parameter parameter, int index)

Due to a bug in javac on JDK versions prior to JDK 9, looking up annotations directly on a Parameter will fail for inner class constructors.

Note

Since Spring 6 may still encounter user code compiled with javac 8, this workaround is kept in place for the time being.

Bug in javac in JDK < 9

The parameter annotations array in the compiled byte code excludes an entry for the implicit enclosing instance parameter for an inner class constructor.

Workaround

This method provides a workaround for this off-by-one error by allowing the caller to access annotations on the preceding Parameter object (i.e., index - 1). If the supplied index is zero, this method returns an empty AnnotatedElement.

WARNING

The AnnotatedElement returned by this method should never be cast and treated as a Parameter since the metadata (e.g., Parameter#getName(), Parameter#getType(), etc.) will not match those for the declared parameter at the given index in an inner class constructor.

Returns:AnnotatedElement

the supplied parameter or the effective Parameter if the aforementioned bug is in effect

isAutowirableback to summary
public static boolean isAutowirable(Parameter parameter, int parameterIndex)

Determine if the supplied Parameter can potentially be autowired from an AutowireCapableBeanFactory.

Returns true if the supplied parameter is annotated or meta-annotated with @Autowired, @Qualifier, or @Value.

Note that resolveDependency may still be able to resolve the dependency for the supplied parameter even if this method returns false.

Parameters
parameter:Parameter

the parameter whose dependency should be autowired (must not be null)

parameterIndex:int

the index of the parameter in the constructor or method that declares the parameter

See Also
resolveDependency
resolveDependencyback to summary
public static Object resolveDependency(Parameter parameter, int parameterIndex, Class<?> containingClass, AutowireCapableBeanFactory beanFactory) throws BeansException

Resolve the dependency for the supplied Parameter from the supplied AutowireCapableBeanFactory.

Provides comprehensive autowiring support for individual method parameters on par with Spring's dependency injection facilities for autowired fields and methods, including support for @Autowired, @Qualifier, and @Value with support for property placeholders and SpEL expressions in @Value declarations.

The dependency is required unless the parameter is annotated or meta-annotated with @Autowired with the required flag set to false.

If an explicit qualifier is not declared, the name of the parameter will be used as the qualifier for resolving ambiguities.

Parameters
parameter:Parameter

the parameter whose dependency should be resolved (must not be null)

parameterIndex:int

the index of the parameter in the constructor or method that declares the parameter

containingClass:Class<?>

the concrete class that contains the parameter; this may differ from the class that declares the parameter in that it may be a subclass thereof, potentially substituting type variables (must not be null)

beanFactory:AutowireCapableBeanFactory

the AutowireCapableBeanFactory from which to resolve the dependency (must not be null)

Returns:Object

the resolved object, or null if none found

Annotations
@Nullable
Exceptions
BeansException:
if dependency resolution failed
See Also
isAutowirable, Autowired#required, SynthesizingMethodParameter#forExecutable(Executable, int), AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String)