Package org.springframework.beans.factory.aot

# Class AutowiredFieldValueResolver

java.lang.Object
org.springframework.beans.factory.aot.AutowiredFieldValueResolver

public final class AutowiredFieldValueResolver extends Object
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).

Since:
  6.0
Author:
  Phillip Webb, Stephane Nicoll

## Method Summary

Modifier and Type
Method
Description
`static AutowiredFieldValueResolver`
`forField(String fieldName)`
Create a new `AutowiredFieldValueResolver` for the specified field where injection is optional.
`static AutowiredFieldValueResolver`
`forRequiredField(String fieldName)`
Create a new `AutowiredFieldValueResolver` for the specified field where injection is required.
`protected final void`
`registerDependentBeans(ConfigurableBeanFactory beanFactory, String beanName, Set<String> autowiredBeanNames)`
`<T> T`
`resolve(RegisteredBean registeredBean)`
Resolve the field value for the specified registered bean.
`<T> T`
`resolve(RegisteredBean registeredBean, Class<T> requiredType)`
Resolve the field value for the specified registered bean.
`<T> void`
`resolve(RegisteredBean registeredBean, org.springframework.util.function.ThrowingConsumer<T> action)`
Resolve the field for the specified registered bean and provide it to the given action.
`void`
`resolveAndSet(RegisteredBean registeredBean, Object instance)`
Resolve the field value for the specified registered bean and set it using reflection.
`Object`
`resolveObject(RegisteredBean registeredBean)`
Resolve the field value for the specified registered bean.
`AutowiredFieldValueResolver`
`withShortcut(String beanName)`
Return a new `AutowiredFieldValueResolver` instance that uses a direct bean name injection shortcut.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### forField

public static AutowiredFieldValueResolver forField(String fieldName)
Create a new `AutowiredFieldValueResolver` for the specified field where injection is optional.

Parameters:
  `fieldName` - the field name
Returns:
  a new `AutowiredFieldValueResolver` instance

### forRequiredField

public static AutowiredFieldValueResolver forRequiredField(String fieldName)
Create a new `AutowiredFieldValueResolver` for the specified field where injection is required.

Parameters:
  `fieldName` - the field name
Returns:
  a new `AutowiredFieldValueResolver` instance

### withShortcut

public AutowiredFieldValueResolver withShortcut(String beanName)
Return a new `AutowiredFieldValueResolver` instance that uses a direct bean name injection shortcut.

Parameters:
  `beanName` - the bean name to use as a shortcut
Returns:
  a new `AutowiredFieldValueResolver` instance that uses the given shortcut bean name

### resolve

public <T> void resolve(RegisteredBean registeredBean, org.springframework.util.function.ThrowingConsumer<T> action)
Resolve the field for the specified registered bean and provide it to the given action.

Parameters:
  `registeredBean` - the registered bean
  `action` - the action to execute with the resolved field value

### resolve

@Nullable public <T> T resolve(RegisteredBean registeredBean, Class<T> requiredType)
Resolve the field value for the specified registered bean.

Parameters:
  `registeredBean` - the registered bean
  `requiredType` - the required type
Returns:
  the resolved field value

### resolve

@Nullable public <T> T resolve(RegisteredBean registeredBean)
Resolve the field value for the specified registered bean.

Parameters:
  `registeredBean` - the registered bean
Returns:
  the resolved field value

### resolveObject

@Nullable public Object resolveObject(RegisteredBean registeredBean)
Resolve the field value for the specified registered bean.

Parameters:
  `registeredBean` - the registered bean
Returns:
  the resolved field value

### resolveAndSet

public void resolveAndSet(RegisteredBean registeredBean, Object instance)
Resolve the field value for the specified registered bean and set it using reflection.

Parameters:
  `registeredBean` - the registered bean
  `instance` - the bean instance

### registerDependentBeans

protected final void registerDependentBeans(ConfigurableBeanFactory beanFactory, String beanName, Set<String> autowiredBeanNames)