Class BeanInstanceSupplier<T>
java.lang.Object
org.springframework.beans.factory.aot.BeanInstanceSupplier<T>
- Type Parameters:
- T- the type of instance supplied by this supplier
- All Implemented Interfaces:
- Supplier<T>,- InstanceSupplier<T>,- ThrowingSupplier<T>
Specialized 
InstanceSupplier that provides the factory Method
 used to instantiate the underlying bean instance, if any. Transparently
 handles resolution of AutowiredArguments if necessary. Typically used
 in AOT-processed applications as a targeted alternative to the reflection
 based injection.
 If no generator is provided, reflection is used to instantiate the
 bean instance, and full invocation hints are
 contributed. Multiple generator callback styles are supported:
 
- A function with the registeredBeanand resolvedargumentsfor executables that require arguments resolution. Anintrospectionhint is added so that parameter annotations can be read
- A function with only the registeredBeanfor simpler cases that do not require resolution of arguments
- A supplier when a method reference can be used
- Since:
- 6.0
- Author:
- Phillip Webb, Stephane Nicoll, Juergen Hoeller
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T> BeanInstanceSupplier<T>forConstructor(Class<?>... parameterTypes) Create aBeanInstanceSupplierthat resolves arguments for the specified bean constructor.static <T> BeanInstanceSupplier<T>forFactoryMethod(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) Create a newBeanInstanceSupplierthat resolves arguments for the specified factory method.get(RegisteredBean registeredBean) Get the supplied instance.Return the factory method that this supplier uses to create the instance, ornullif it is not known or this supplier uses another means.protected final voidregisterDependentBeans(ConfigurableBeanFactory beanFactory, String beanName, Set<String> autowiredBeanNames) withGenerator(ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generator) Return a newBeanInstanceSupplierinstance that uses the specifiedgeneratorbi-function to instantiate the underlying bean.withGenerator(ThrowingFunction<RegisteredBean, T> generator) Return a newBeanInstanceSupplierinstance that uses the specifiedgeneratorfunction to instantiate the underlying bean.withGenerator(ThrowingSupplier<T> generator) Deprecated, for removal: This API element is subject to removal in a future version.withShortcut(String... beanNames) Return a newBeanInstanceSupplierinstance that uses direct bean name injection shortcuts for specific parameters.withShortcuts(String... beanNames) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofwithShortcut(String...)Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.support.InstanceSupplierandThen, getWithExceptionMethods inherited from interface org.springframework.util.function.ThrowingSupplierget, get, throwing
- 
Method Details- 
forConstructorCreate aBeanInstanceSupplierthat resolves arguments for the specified bean constructor.- Type Parameters:
- T- the type of instance supplied
- Parameters:
- parameterTypes- the constructor parameter types
- Returns:
- a new BeanInstanceSupplierinstance
 
- 
forFactoryMethodpublic static <T> BeanInstanceSupplier<T> forFactoryMethod(Class<?> declaringClass, String methodName, Class<?>... parameterTypes) Create a newBeanInstanceSupplierthat resolves arguments for the specified factory method.- Type Parameters:
- T- the type of instance supplied
- Parameters:
- declaringClass- the class that declares the factory method
- methodName- the factory method name
- parameterTypes- the factory method parameter types
- Returns:
- a new BeanInstanceSupplierinstance
 
- 
withGeneratorpublic BeanInstanceSupplier<T> withGenerator(ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generator) Return a newBeanInstanceSupplierinstance that uses the specifiedgeneratorbi-function to instantiate the underlying bean.- Parameters:
- generator- a- ThrowingBiFunctionthat uses the- RegisteredBeanand resolved- AutowiredArgumentsto instantiate the underlying bean
- Returns:
- a new BeanInstanceSupplierinstance with the specified generator
 
- 
withGeneratorReturn a newBeanInstanceSupplierinstance that uses the specifiedgeneratorfunction to instantiate the underlying bean.- Parameters:
- generator- a- ThrowingFunctionthat uses the- RegisteredBeanto instantiate the underlying bean
- Returns:
- a new BeanInstanceSupplierinstance with the specified generator
 
- 
withGenerator@Deprecated(since="6.0.11", forRemoval=true) public BeanInstanceSupplier<T> withGenerator(ThrowingSupplier<T> generator) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofwithGenerator(ThrowingFunction)Return a newBeanInstanceSupplierinstance that uses the specifiedgeneratorsupplier to instantiate the underlying bean.- Parameters:
- generator- a- ThrowingSupplierto instantiate the underlying bean
- Returns:
- a new BeanInstanceSupplierinstance with the specified generator
 
- 
withShortcuts@Deprecated(since="6.2", forRemoval=true) public BeanInstanceSupplier<T> withShortcuts(String... beanNames) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofwithShortcut(String...)Return a newBeanInstanceSupplierinstance that uses direct bean name injection shortcuts for specific parameters.
- 
withShortcutReturn a newBeanInstanceSupplierinstance that uses direct bean name injection shortcuts for specific parameters.- Parameters:
- beanNames- the bean names to use as shortcut (aligned with the constructor or factory method parameters)
- Returns:
- a new BeanInstanceSupplierinstance that uses the given shortcut bean names
- Since:
- 6.2
 
- 
getDescription copied from interface:InstanceSupplierGet the supplied instance.- Specified by:
- getin interface- InstanceSupplier<T>
- Parameters:
- registeredBean- the registered bean requesting the instance
- Returns:
- the supplied instance
 
- 
getFactoryMethodDescription copied from interface:InstanceSupplierReturn the factory method that this supplier uses to create the instance, ornullif it is not known or this supplier uses another means.- Specified by:
- getFactoryMethodin interface- InstanceSupplier<T>
- Returns:
- the factory method used to create the instance, or null
 
- 
registerDependentBeansprotected final void registerDependentBeans(ConfigurableBeanFactory beanFactory, String beanName, Set<String> autowiredBeanNames) 
 
- 
withGenerator(ThrowingFunction)