Class AutowiredMethodArgumentsResolver

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

public final class AutowiredMethodArgumentsResolver extends Object
Resolver used to support the autowiring of methods. Typically used in AOT-processed applications as a targeted alternative to the AutowiredAnnotationBeanPostProcessor.

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

Since:
6.0
Author:
Phillip Webb, Stephane Nicoll
  • Method Details

    • forMethod

      public static AutowiredMethodArgumentsResolver forMethod(String methodName, Class<?>... parameterTypes)
      Create a new AutowiredMethodArgumentsResolver for the specified method where injection is optional.
      Parameters:
      methodName - the method name
      parameterTypes - the factory method parameter types
      Returns:
      a new AutowiredFieldValueResolver instance
    • forRequiredMethod

      public static AutowiredMethodArgumentsResolver forRequiredMethod(String methodName, Class<?>... parameterTypes)
      Create a new AutowiredMethodArgumentsResolver for the specified method where injection is required.
      Parameters:
      methodName - the method name
      parameterTypes - the factory method parameter types
      Returns:
      a new AutowiredFieldValueResolver instance
    • withShortcut

      public AutowiredMethodArgumentsResolver withShortcut(String... beanNames)
      Return a new AutowiredMethodArgumentsResolver instance that uses direct bean name injection shortcuts for specific parameters.
      Parameters:
      beanNames - the bean names to use as shortcuts (aligned with the method parameters)
      Returns:
      a new AutowiredMethodArgumentsResolver instance that uses the shortcuts
    • resolve

      public void resolve(RegisteredBean registeredBean, org.springframework.util.function.ThrowingConsumer<AutowiredArguments> action)
      Resolve the method arguments 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 method arguments
    • resolve

      @Nullable public AutowiredArguments resolve(RegisteredBean registeredBean)
      Resolve the method arguments for the specified registered bean.
      Parameters:
      registeredBean - the registered bean
      Returns:
      the resolved method arguments
    • resolveAndInvoke

      public void resolveAndInvoke(RegisteredBean registeredBean, Object instance)
      Resolve the method arguments for the specified registered bean and invoke the method using reflection.
      Parameters:
      registeredBean - the registered bean
      instance - the bean instance
    • registerDependentBeans

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