public final class ParameterResolutionDelegate
extends java.lang.Object
isAutowirable(java.lang.reflect.Parameter, int)
,
resolveDependency(java.lang.reflect.Parameter, int, java.lang.Class<?>, org.springframework.beans.factory.config.AutowireCapableBeanFactory)
Modifier and Type | Field and Description |
---|---|
private static java.lang.reflect.AnnotatedElement |
EMPTY_ANNOTATED_ELEMENT |
Modifier | Constructor and Description |
---|---|
private |
ParameterResolutionDelegate() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.reflect.AnnotatedElement |
getEffectiveAnnotatedParameter(java.lang.reflect.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. |
static boolean |
isAutowirable(java.lang.reflect.Parameter parameter,
int parameterIndex)
Determine if the supplied
Parameter can potentially be
autowired from an AutowireCapableBeanFactory . |
static java.lang.Object |
resolveDependency(java.lang.reflect.Parameter parameter,
int parameterIndex,
java.lang.Class<?> containingClass,
AutowireCapableBeanFactory beanFactory)
Resolve the dependency for the supplied
Parameter from the
supplied AutowireCapableBeanFactory . |
private static final java.lang.reflect.AnnotatedElement EMPTY_ANNOTATED_ELEMENT
public static boolean isAutowirable(java.lang.reflect.Parameter parameter, int parameterIndex)
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(java.lang.reflect.Parameter, int, java.lang.Class<?>, org.springframework.beans.factory.config.AutowireCapableBeanFactory)
may still be able to resolve the
dependency for the supplied parameter even if this method returns false
.
parameter
- the parameter whose dependency should be autowired
(must not be null
)parameterIndex
- the index of the parameter in the constructor or method
that declares the parameterresolveDependency(java.lang.reflect.Parameter, int, java.lang.Class<?>, org.springframework.beans.factory.config.AutowireCapableBeanFactory)
@Nullable public static java.lang.Object resolveDependency(java.lang.reflect.Parameter parameter, int parameterIndex, java.lang.Class<?> containingClass, AutowireCapableBeanFactory beanFactory) throws BeansException
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.
parameter
- the parameter whose dependency should be resolved (must not be
null
)parameterIndex
- the index of the parameter in the constructor or method
that declares the parametercontainingClass
- 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
- the AutowireCapableBeanFactory
from which to resolve
the dependency (must not be null
)null
if none foundBeansException
- if dependency resolution failedisAutowirable(java.lang.reflect.Parameter, int)
,
Autowired.required()
,
SynthesizingMethodParameter.forExecutable(Executable, int)
,
AutowireCapableBeanFactory.resolveDependency(DependencyDescriptor, String)
private static java.lang.reflect.AnnotatedElement getEffectiveAnnotatedParameter(java.lang.reflect.Parameter parameter, int index)
javac
on JDK versions prior to JDK 9, looking up
annotations directly on a Parameter
will fail for inner class
constructors.
The parameter annotations array in the compiled byte code excludes an entry for the implicit enclosing instance parameter for an inner class constructor.
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
.
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.
parameter
or the effective Parameter
if the aforementioned bug is in effect