Class AutowiredInstantiationArgumentsResolver

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

public final class AutowiredInstantiationArgumentsResolver extends Object
Resolver used to support the autowiring of constructors or factory methods. Typically used in AOT-processed applications as a targeted alternative to the reflection based injection.

When resolving arguments in a native image, the Constructor or Method being used must be marked with an introspection hint so that parameter annotations can be read. Full invocation hints are only required if the resolveAndInstantiate methods of this class are being used (typically to support private constructors, methods or classes).

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

    • forConstructor

      public static AutowiredInstantiationArgumentsResolver forConstructor(Class<?>... parameterTypes)
      Create a AutowiredInstantiationArgumentsResolver that resolves arguments for the specified bean constructor.
      Parameters:
      parameterTypes - the constructor parameter types
      Returns:
      a new AutowiredInstantiationArgumentsResolver instance
    • forFactoryMethod

      public static AutowiredInstantiationArgumentsResolver forFactoryMethod(Class<?> declaringClass, String methodName, Class<?>... parameterTypes)
      Create a new AutowiredInstantiationArgumentsResolver that resolves arguments for the specified factory method.
      Parameters:
      declaringClass - the class that declares the factory method
      methodName - the factory method name
      parameterTypes - the factory method parameter types
      Returns:
      a new AutowiredInstantiationArgumentsResolver instance
    • withShortcuts

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

      public <T> T resolve(RegisteredBean registeredBean, ThrowingFunction<AutowiredArguments,T> generator)
      Resolve arguments for the specified registered bean and provide them to the given generator in order to return a result.
      Parameters:
      registeredBean - the registered bean
      generator - the generator to execute with the resolved constructor or factory method arguments
    • resolve

      public AutowiredArguments resolve(RegisteredBean registeredBean)
      Resolve arguments for the specified registered bean.
      Parameters:
      registeredBean - the registered bean
      Returns:
      the resolved constructor or factory method arguments
    • resolveAndInstantiate

      public <T> T resolveAndInstantiate(RegisteredBean registeredBean)
      Resolve arguments for the specified registered bean and instantiate a new instance using reflection.
      Parameters:
      registeredBean - the registered bean
      Returns:
      an instance of the bean
    • resolveAndInstantiate

      public <T> T resolveAndInstantiate(RegisteredBean registeredBean, Class<T> requiredType)
      Resolve arguments for the specified registered bean and instantiate a new instance using reflection.
      Parameters:
      registeredBean - the registered bean
      requiredType - the required result type
      Returns:
      an instance of the bean
    • registerDependentBeans

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