abstract class ParameterAutowireUtils
extends java.lang.Object
isAutowirable(java.lang.reflect.Parameter, int)
,
resolveDependency(java.lang.reflect.Parameter, int, java.lang.Class<?>, org.springframework.context.ApplicationContext)
Modifier and Type | Field and Description |
---|---|
private static java.lang.reflect.AnnotatedElement |
EMPTY_ANNOTATED_ELEMENT |
Constructor and Description |
---|
ParameterAutowireUtils() |
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. |
(package private) static boolean |
isAutowirable(java.lang.reflect.Parameter parameter,
int parameterIndex)
Determine if the supplied
Parameter can potentially be
autowired from an ApplicationContext . |
(package private) static java.lang.Object |
resolveDependency(java.lang.reflect.Parameter parameter,
int parameterIndex,
java.lang.Class<?> containingClass,
ApplicationContext applicationContext)
Resolve the dependency for the supplied
Parameter from the
supplied ApplicationContext . |
private static final java.lang.reflect.AnnotatedElement EMPTY_ANNOTATED_ELEMENT
static boolean isAutowirable(java.lang.reflect.Parameter parameter, int parameterIndex)
Parameter
can potentially be
autowired from an ApplicationContext
.
Returns true
if the supplied parameter is of type
ApplicationContext
(or a sub-type thereof) or is annotated or
meta-annotated with @Autowired
,
@Qualifier
, or @Value
.
parameter
- the parameter whose dependency should be autowiredparameterIndex
- the index of the parameterresolveDependency(java.lang.reflect.Parameter, int, java.lang.Class<?>, org.springframework.context.ApplicationContext)
@Nullable static java.lang.Object resolveDependency(java.lang.reflect.Parameter parameter, int parameterIndex, java.lang.Class<?> containingClass, ApplicationContext applicationContext)
Parameter
from the
supplied ApplicationContext
.
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 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 resolvedparameterIndex
- the index of 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 variablesapplicationContext
- the application context from which to resolve the
dependencynull
if none foundBeansException
- if dependency resolution failedisAutowirable(java.lang.reflect.Parameter, int)
,
Autowired.required()
,
SynthesizingMethodParameter.forParameter(Parameter)
,
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