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

public final Class AutowiredFieldValueResolver

extends AutowiredElementResolver
Class Inheritance
Imports
java.lang.reflect.Field, java.util.LinkedHashSet, .Set, org.springframework.aot.hint.ExecutableMode, org.springframework.beans.BeansException, .TypeConverter, org.springframework.beans.factory.InjectionPoint, .UnsatisfiedDependencyException, org.springframework.beans.factory.config.AutowireCapableBeanFactory, .ConfigurableBeanFactory, .DependencyDescriptor, org.springframework.beans.factory.support.RegisteredBean, org.springframework.lang.Nullable, org.springframework.util.Assert, .ReflectionUtils, org.springframework.util.function.ThrowingConsumer

Resolver used to support the autowiring of fields. Typically used in AOT-processed applications as a targeted alternative to the AutowiredAnnotationBeanPostProcessor.

When resolving arguments in a native image, the Field being used must be marked with an introspection hint so that field annotations can be read. Full invocation hints are only required if the resolveAndSet(RegisteredBean, Object) method of this class is being used (typically to support private fields).

Authors
Phillip Webb, Stephane Nicoll
Since
6.0

Field Summary

Modifier and TypeField and Description
private final String
private final boolean
private final String

Constructor Summary

AccessConstructor and Description
private
AutowiredFieldValueResolver(String fieldName, boolean required, String shortcut)

Method Summary

Modifier and TypeMethod and Description
public static AutowiredFieldValueResolver

Returns:

a new AutowiredFieldValueResolver instance
forField
(String
the field name
fieldName
)

Create a new AutowiredFieldValueResolver for the specified field where injection is optional.

public static AutowiredFieldValueResolver

Returns:

a new AutowiredFieldValueResolver instance
forRequiredField
(String
the field name
fieldName
)

Create a new AutowiredFieldValueResolver for the specified field where injection is required.

private Field
getField(RegisteredBean registeredBean)

public <T> void
resolve(RegisteredBean
the registered bean
registeredBean
,
ThrowingConsumer<T>
the action to execute with the resolved field value
action
)

Resolve the field for the specified registered bean and provide it to the given action.

public <T> T

Returns:

the resolved field value
resolve
(RegisteredBean
the registered bean
registeredBean
,
Class<T>
the required type
requiredType
)

Resolve the field value for the specified registered bean.

public <T> T

Returns:

the resolved field value
resolve
(RegisteredBean
the registered bean
registeredBean
)

Resolve the field value for the specified registered bean.

public void
resolveAndSet(RegisteredBean
the registered bean
registeredBean
,
Object
the bean instance
instance
)

Resolve the field value for the specified registered bean and set it using reflection.

public Object

Returns:

the resolved field value
resolveObject
(RegisteredBean
the registered bean
registeredBean
)

Resolve the field value for the specified registered bean.

private Object
resolveValue(RegisteredBean registeredBean, Field field)

public AutowiredFieldValueResolver

Returns:

a new AutowiredFieldValueResolver instance that uses the shortcuts
withShortcut
(String
the bean name to use as a shortcut
beanName
)

Return a new AutowiredFieldValueResolver instance that uses a direct bean name injection shortcut.

Inherited from org.springframework.beans.factory.aot.AutowiredElementResolver:
registerDependentBeans

Field Detail

fieldNameback to summary
private final String fieldName
requiredback to summary
private final boolean required
shortcutback to summary
private final String shortcut
Annotations
@Nullable

Constructor Detail

AutowiredFieldValueResolverback to summary
private AutowiredFieldValueResolver(String fieldName, boolean required, String shortcut)

Method Detail

forFieldback to summary
public static AutowiredFieldValueResolver forField(String fieldName)

Create a new AutowiredFieldValueResolver for the specified field where injection is optional.

Parameters
fieldName:String

the field name

Returns:AutowiredFieldValueResolver

a new AutowiredFieldValueResolver instance

forRequiredFieldback to summary
public static AutowiredFieldValueResolver forRequiredField(String fieldName)

Create a new AutowiredFieldValueResolver for the specified field where injection is required.

Parameters
fieldName:String

the field name

Returns:AutowiredFieldValueResolver

a new AutowiredFieldValueResolver instance

getFieldback to summary
private Field getField(RegisteredBean registeredBean)
resolveback to summary
public <T> void resolve(RegisteredBean registeredBean, ThrowingConsumer<T> action)

Resolve the field for the specified registered bean and provide it to the given action.

Parameters
registeredBean:RegisteredBean

the registered bean

action:ThrowingConsumer<T>

the action to execute with the resolved field value

resolveback to summary
public <T> T resolve(RegisteredBean registeredBean, Class<T> requiredType)

Resolve the field value for the specified registered bean.

Parameters
registeredBean:RegisteredBean

the registered bean

requiredType:Class<T>

the required type

Returns:T

the resolved field value

Annotations
@Nullable
@SuppressWarnings:unchecked
resolveback to summary
public <T> T resolve(RegisteredBean registeredBean)

Resolve the field value for the specified registered bean.

Parameters
registeredBean:RegisteredBean

the registered bean

Returns:T

the resolved field value

Annotations
@Nullable
@SuppressWarnings:unchecked
resolveAndSetback to summary
public void resolveAndSet(RegisteredBean registeredBean, Object instance)

Resolve the field value for the specified registered bean and set it using reflection.

Parameters
registeredBean:RegisteredBean

the registered bean

instance:Object

the bean instance

resolveObjectback to summary
public Object resolveObject(RegisteredBean registeredBean)

Resolve the field value for the specified registered bean.

Parameters
registeredBean:RegisteredBean

the registered bean

Returns:Object

the resolved field value

Annotations
@Nullable
resolveValueback to summary
private Object resolveValue(RegisteredBean registeredBean, Field field)
Annotations
@Nullable
withShortcutback to summary
public AutowiredFieldValueResolver withShortcut(String beanName)

Return a new AutowiredFieldValueResolver instance that uses a direct bean name injection shortcut.

Parameters
beanName:String

the bean name to use as a shortcut

Returns:AutowiredFieldValueResolver

a new AutowiredFieldValueResolver instance that uses the shortcuts