Class InstanceSupplierCodeGenerator

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

public class InstanceSupplierCodeGenerator extends Object
Default code generator to create an InstanceSupplier, usually in the form of a BeanInstanceSupplier that retains the executable that is used to instantiate the bean. Takes care of registering the necessary hints if reflection or a JDK proxy is required.

Generated code is usually a method reference that generates the BeanInstanceSupplier, but some shortcut can be used as well such as:

 InstanceSupplier.of(TheGeneratedClass::getMyBeanInstance);
 
Since:
6.0
Author:
Phillip Webb, Stephane Nicoll, Juergen Hoeller, Sebastien Deleuze
See Also:
  • Constructor Details

    • InstanceSupplierCodeGenerator

      public InstanceSupplierCodeGenerator(GenerationContext generationContext, org.springframework.javapoet.ClassName className, GeneratedMethods generatedMethods, boolean allowDirectSupplierShortcut)
      Create a new instance.
      Parameters:
      generationContext - the generation context
      className - the class name of the bean to instantiate
      generatedMethods - the generated methods
      allowDirectSupplierShortcut - whether a direct supplier may be used rather than always needing an InstanceSupplier
  • Method Details

    • generateCode

      public org.springframework.javapoet.CodeBlock generateCode(RegisteredBean registeredBean, Executable constructorOrFactoryMethod)
      Generate the instance supplier code.
      Parameters:
      registeredBean - the bean to handle
      constructorOrFactoryMethod - the executable to use to create the bean
      Returns:
      the generated code