Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.config

public Class DependencyDescriptor

extends InjectionPoint
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.AutowireByTypeDependencyDescriptor, org.springframework.beans.factory.support.ConstructorResolver.ConstructorDependencyDescriptor, org.springframework.beans.factory.support.DefaultListableBeanFactory.NestedDependencyDescriptor, org.springframework.beans.factory.support.DefaultListableBeanFactory.StreamDependencyDescriptor, org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.ShortcutDependencyDescriptor, org.springframework.beans.factory.aot.AutowiredElementResolver.ShortcutDependencyDescriptor
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .ObjectInputStream, .Serializable, java.lang.annotation.Annotation, java.lang.reflect.Field, java.util.Map, .Optional, kotlin.reflect.KProperty, kotlin.reflect.jvm.ReflectJvmMapping, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .InjectionPoint, .NoUniqueBeanDefinitionException, org.springframework.core.KotlinDetector, .MethodParameter, .ParameterNameDiscoverer, .ResolvableType, org.springframework.core.convert.TypeDescriptor, org.springframework.lang.Nullable, org.springframework.util.ObjectUtils

Descriptor for a specific dependency that is about to be injected. Wraps a constructor parameter, a method parameter or a field, allowing unified access to their metadata.
Author
Juergen Hoeller
Since
2.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DependencyDescriptor.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

Field Summary

Modifier and TypeField and Description
private Class<?>
private final Class<?>
private final boolean
private String
private String
private int
private int
private Class<?>[]
private final boolean
private transient volatile ResolvableType
private transient volatile TypeDescriptor
Inherited from org.springframework.beans.factory.InjectionPoint:
fieldmethodParameter

Constructor Summary

AccessConstructor and Description
public
DependencyDescriptor(MethodParameter
the MethodParameter to wrap
methodParameter
,
boolean
whether the dependency is required
required
)

Create a new descriptor for a method or constructor parameter.

public
DependencyDescriptor(MethodParameter
the MethodParameter to wrap
methodParameter
,
boolean
whether the dependency is required
required
,
boolean
whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching
eager
)

Create a new descriptor for a method or constructor parameter.

public
DependencyDescriptor(Field
the field to wrap
field
,
boolean
whether the dependency is required
required
)

Create a new descriptor for a field.

public
DependencyDescriptor(Field
the field to wrap
field
,
boolean
whether the dependency is required
required
,
boolean
whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching
eager
)

Create a new descriptor for a field.

public
DependencyDescriptor(DependencyDescriptor
the original descriptor to create a copy from
original
)

Copy constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides org.springframework.beans.factory.InjectionPoint.equals.

Indicates whether some other object is "equal to" this one.
public boolean
fallbackMatchAllowed()

Return whether a fallback match is allowed.

public DependencyDescriptor
forFallbackMatch()

Return a variant of this descriptor that is intended for a fallback match.

public String

Returns:

the declared name (may be null if unresolvable)
getDependencyName
()

Determine the name of the wrapped parameter/field.

public Class<?>

Returns:

the declared type (never null)
getDependencyType
()

Determine the declared (non-generic) type of the wrapped parameter/field.

public ResolvableType
getResolvableType()

Build a ResolvableType object for the wrapped parameter/field.

public TypeDescriptor
getTypeDescriptor()

Build a TypeDescriptor object for the wrapped parameter/field.

public int
hashCode()

Overrides org.springframework.beans.factory.InjectionPoint.hashCode.

Returns a hash code value for the object.
private boolean
hasNullableAnnotation()

Check whether the underlying field is annotated with any variant of a Nullable annotation, e.g. jakarta.annotation.Nullable or edu.umd.cs.findbugs.annotations.Nullable.

public void
increaseNestingLevel()

Increase this descriptor's nesting level.

public void
initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)

Initialize parameter name discovery for the underlying method parameter, if any.

public boolean
isEager()

Return whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching.

public boolean
isRequired()

Return whether this dependency is required.

private void
public Object

Returns:

the bean instance (never null)
resolveCandidate
(String
the bean name, as a candidate result for this dependency
beanName
,
Class<?>
the expected type of the bean (as an assertion)
requiredType
,
BeanFactory
the associated factory
beanFactory
)

Resolve the specified bean name, as a candidate result of the matching algorithm for this dependency, to a bean instance from the given factory.

public Object

Returns:

a bean instance to proceed with, or null for none
resolveNotUnique
(ResolvableType
the requested bean type
type
,
Map<String, Object>
a map of bean names and corresponding bean instances which have been pre-selected for the given type (qualifiers etc already applied)
matchingBeans
)

Resolve the specified not-unique scenario: by default, throwing a NoUniqueBeanDefinitionException.

public Object

Returns:

the shortcut result if any, or null if none
resolveShortcut
(BeanFactory
the associated factory
beanFactory
)

Resolve a shortcut for this dependency against the given factory, for example taking some pre-resolved information into account.

public void
setContainingClass(Class<?> containingClass)

Optionally set the concrete class that contains this dependency.

public boolean
supportsLazyResolution()

Determine whether this dependency supports lazy resolution, e.g. through extra proxying.

Inherited from org.springframework.beans.factory.InjectionPoint:
getAnnotatedElementgetAnnotationgetAnnotationsgetDeclaredTypegetFieldgetMembergetMethodParameterobtainMethodParametertoString

Field Detail

containingClassback to summary
private Class<?> containingClass
Annotations
@Nullable
declaringClassback to summary
private final Class<?> declaringClass
eagerback to summary
private final boolean eager
fieldNameback to summary
private String fieldName
Annotations
@Nullable
methodNameback to summary
private String methodName
Annotations
@Nullable
nestingLevelback to summary
private int nestingLevel
parameterIndexback to summary
private int parameterIndex
parameterTypesback to summary
private Class<?>[] parameterTypes
Annotations
@Nullable
requiredback to summary
private final boolean required
resolvableTypeback to summary
private transient volatile ResolvableType resolvableType
Annotations
@Nullable
typeDescriptorback to summary
private transient volatile TypeDescriptor typeDescriptor
Annotations
@Nullable

Constructor Detail

DependencyDescriptorback to summary
public DependencyDescriptor(MethodParameter methodParameter, boolean required)

Create a new descriptor for a method or constructor parameter. Considers the dependency as 'eager'.

Parameters
methodParameter:MethodParameter

the MethodParameter to wrap

required:boolean

whether the dependency is required

DependencyDescriptorback to summary
public DependencyDescriptor(MethodParameter methodParameter, boolean required, boolean eager)

Create a new descriptor for a method or constructor parameter.

Parameters
methodParameter:MethodParameter

the MethodParameter to wrap

required:boolean

whether the dependency is required

eager:boolean

whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching

DependencyDescriptorback to summary
public DependencyDescriptor(Field field, boolean required)

Create a new descriptor for a field. Considers the dependency as 'eager'.

Parameters
field:Field

the field to wrap

required:boolean

whether the dependency is required

DependencyDescriptorback to summary
public DependencyDescriptor(Field field, boolean required, boolean eager)

Create a new descriptor for a field.

Parameters
field:Field

the field to wrap

required:boolean

whether the dependency is required

eager:boolean

whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching

DependencyDescriptorback to summary
public DependencyDescriptor(DependencyDescriptor original)

Copy constructor.

Parameters
original:DependencyDescriptor

the original descriptor to create a copy from

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides org.springframework.beans.factory.InjectionPoint.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fallbackMatchAllowedback to summary
public boolean fallbackMatchAllowed()

Return whether a fallback match is allowed.

This is false by default but may be overridden to return true in order to suggest to an org.springframework.beans.factory.support.AutowireCandidateResolver that a fallback match is acceptable as well.

Since
4.0
forFallbackMatchback to summary
public DependencyDescriptor forFallbackMatch()

Return a variant of this descriptor that is intended for a fallback match.

Since
4.0
See Also
fallbackMatchAllowed()
getDependencyNameback to summary
public String getDependencyName()

Determine the name of the wrapped parameter/field.

Returns:String

the declared name (may be null if unresolvable)

Annotations
@Nullable
getDependencyTypeback to summary
public Class<?> getDependencyType()

Determine the declared (non-generic) type of the wrapped parameter/field.

Returns:Class<?>

the declared type (never null)

getResolvableTypeback to summary
public ResolvableType getResolvableType()

Build a ResolvableType object for the wrapped parameter/field.

Since
4.0
getTypeDescriptorback to summary
public TypeDescriptor getTypeDescriptor()

Build a TypeDescriptor object for the wrapped parameter/field.

Since
5.1.4
hashCodeback to summary
public int hashCode()

Overrides org.springframework.beans.factory.InjectionPoint.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hasNullableAnnotationback to summary
private boolean hasNullableAnnotation()

Check whether the underlying field is annotated with any variant of a Nullable annotation, e.g. jakarta.annotation.Nullable or edu.umd.cs.findbugs.annotations.Nullable.

increaseNestingLevelback to summary
public void increaseNestingLevel()

Increase this descriptor's nesting level.

initParameterNameDiscoveryback to summary
public void initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)

Initialize parameter name discovery for the underlying method parameter, if any.

This method does not actually try to retrieve the parameter name at this point; it just allows discovery to happen when the application calls getDependencyName() (if ever).

isEagerback to summary
public boolean isEager()

Return whether this dependency is 'eager' in the sense of eagerly resolving potential target beans for type matching.

isRequiredback to summary
public boolean isRequired()

Return whether this dependency is required.

Optional semantics are derived from Java 8's java.util.Optional, any variant of a parameter-level Nullable annotation (such as from JSR-305 or the FindBugs set of annotations), or a language-level nullable type declaration in Kotlin.

readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
resolveCandidateback to summary
public Object resolveCandidate(String beanName, Class<?> requiredType, BeanFactory beanFactory) throws BeansException

Resolve the specified bean name, as a candidate result of the matching algorithm for this dependency, to a bean instance from the given factory.

The default implementation calls BeanFactory#getBean(String). Subclasses may provide additional arguments or other customizations.

Parameters
beanName:String

the bean name, as a candidate result for this dependency

requiredType:Class<?>

the expected type of the bean (as an assertion)

beanFactory:BeanFactory

the associated factory

Returns:Object

the bean instance (never null)

Exceptions
BeansException:
if the bean could not be obtained
Since
4.3.2
See Also
BeanFactory#getBean(String)
resolveNotUniqueback to summary
public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) throws BeansException

Resolve the specified not-unique scenario: by default, throwing a NoUniqueBeanDefinitionException.

Subclasses may override this to select one of the instances or to opt out with no result at all through returning null.

Parameters
type:ResolvableType

the requested bean type

matchingBeans:Map<String, Object>

a map of bean names and corresponding bean instances which have been pre-selected for the given type (qualifiers etc already applied)

Returns:Object

a bean instance to proceed with, or null for none

Annotations
@Nullable
Exceptions
BeansException:
in case of the not-unique scenario being fatal
Since
5.1
resolveShortcutback to summary
public Object resolveShortcut(BeanFactory beanFactory) throws BeansException

Resolve a shortcut for this dependency against the given factory, for example taking some pre-resolved information into account.

The resolution algorithm will first attempt to resolve a shortcut through this method before going into the regular type matching algorithm across all beans. Subclasses may override this method to improve resolution performance based on pre-cached information while still receiving InjectionPoint exposure etc.

Parameters
beanFactory:BeanFactory

the associated factory

Returns:Object

the shortcut result if any, or null if none

Annotations
@Nullable
Exceptions
BeansException:
if the shortcut could not be obtained
Since
4.3.1
setContainingClassback to summary
public void setContainingClass(Class<?> containingClass)

Optionally set the concrete class that contains this dependency. This may differ from the class that declares the parameter/field in that it may be a subclass thereof, potentially substituting type variables.

Since
4.0
supportsLazyResolutionback to summary
public boolean supportsLazyResolution()

Determine whether this dependency supports lazy resolution, e.g. through extra proxying. The default is true.

Since
6.1.2
See Also
org.springframework.beans.factory.support.AutowireCandidateResolver#getLazyResolutionProxyIfNecessary
org.springframework.beans.factory.config back to summary

private Class DependencyDescriptor.KotlinDelegate

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.config.DependencyDescriptor.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean
isNullable(Field field)

Check whether the specified Field represents a nullable Kotlin type or not.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

KotlinDelegateback to summary
private KotlinDelegate()

Method Detail

isNullableback to summary
public static boolean isNullable(Field field)

Check whether the specified Field represents a nullable Kotlin type or not.