@ -89,6 +89,31 @@ public final class ParameterResolutionDelegate {
@@ -89,6 +89,31 @@ public final class ParameterResolutionDelegate {
AnnotatedElementUtils . hasAnnotation ( annotatedParameter , Value . class ) ) ;
}
/ * *
* Resolve the dependency for the supplied { @link Parameter } from the
* supplied { @link AutowireCapableBeanFactory } .
* < p > See { @link # resolveDependency ( Parameter , int , String , Class , AutowireCapableBeanFactory ) }
* for details .
* @param parameter the parameter whose dependency should be resolved ( must not be
* { @code null } )
* @param parameterIndex the index of the parameter in the constructor or method
* that declares the parameter
* @param containingClass 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 { @code null } )
* @param beanFactory the { @code AutowireCapableBeanFactory } from which to resolve
* the dependency ( must not be { @code null } )
* @return the resolved object , or { @code null } if none found
* @throws BeansException if dependency resolution failed
* @see # resolveDependency ( Parameter , int , String , Class , AutowireCapableBeanFactory )
* /
public static @Nullable Object resolveDependency (
Parameter parameter , int parameterIndex , Class < ? > containingClass , AutowireCapableBeanFactory beanFactory )
throws BeansException {
return resolveDependency ( parameter , parameterIndex , null , containingClass , beanFactory ) ;
}
/ * *
* Resolve the dependency for the supplied { @link Parameter } from the
* supplied { @link AutowireCapableBeanFactory } .
@ -101,11 +126,13 @@ public final class ParameterResolutionDelegate {
@@ -101,11 +126,13 @@ public final class ParameterResolutionDelegate {
* with { @link Autowired @Autowired } with the { @link Autowired # required required }
* flag set to { @code false } .
* < p > If an explicit < em > qualifier < / em > is not declared , the name of the parameter
* will be used as the qualifier for resolving ambiguities .
* ( or a supplied custom name ) will be used as the qualifier for resolving ambiguities .
* @param parameter the parameter whose dependency should be resolved ( must not be
* { @code null } )
* @param parameterIndex the index of the parameter in the constructor or method
* that declares the parameter
* @param parameterName a custom name for the parameter ; or { @code null } to use
* the default parameter name discovery logic
* @param containingClass 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 { @code null } )
@ -113,13 +140,14 @@ public final class ParameterResolutionDelegate {
@@ -113,13 +140,14 @@ public final class ParameterResolutionDelegate {
* the dependency ( must not be { @code null } )
* @return the resolved object , or { @code null } if none found
* @throws BeansException if dependency resolution failed
* @since 7 . 1
* @see # isAutowirable
* @see Autowired # required
* @see SynthesizingMethodParameter # forExecutable ( Executable , int )
* @see AutowireCapableBeanFactory # resolveDependency ( DependencyDescriptor , String )
* /
public static @Nullable Object resolveDependency (
Parameter parameter , int parameterIndex , Class < ? > containingClass , AutowireCapableBeanFactory beanFactory )
public static @Nullable Object resolveDependency ( Parameter parameter , int parameterIndex ,
@Nullable String parameterName , Class < ? > containingClass , AutowireCapableBeanFactory beanFactory )
throws BeansException {
Assert . notNull ( parameter , "Parameter must not be null" ) ;
@ -132,7 +160,7 @@ public final class ParameterResolutionDelegate {
@@ -132,7 +160,7 @@ public final class ParameterResolutionDelegate {
MethodParameter methodParameter = SynthesizingMethodParameter . forExecutable (
parameter . getDeclaringExecutable ( ) , parameterIndex ) ;
DependencyDescriptor descriptor = new DependencyDescriptor ( methodParameter , required ) ;
DependencyDescriptor descriptor = new NamedParameter DependencyDescriptor( methodParameter , required , parameterName ) ;
descriptor . setContainingClass ( containingClass ) ;
return beanFactory . resolveDependency ( descriptor , null ) ;
}
@ -171,4 +199,26 @@ public final class ParameterResolutionDelegate {
@@ -171,4 +199,26 @@ public final class ParameterResolutionDelegate {
return parameter ;
}
@SuppressWarnings ( "serial" )
private static class NamedParameterDependencyDescriptor extends DependencyDescriptor {
private final @Nullable String parameterName ;
NamedParameterDependencyDescriptor ( MethodParameter methodParameter , boolean required , @Nullable String parameterName ) {
super ( methodParameter , required ) ;
this . parameterName = parameterName ;
}
@Override
public @Nullable String getDependencyName ( ) {
return ( this . parameterName ! = null ? this . parameterName : super . getDependencyName ( ) ) ;
}
@Override
public boolean usesStandardBeanLookup ( ) {
return true ;
}
}
}