Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.aot

public final Class BeanInstanceSupplier<T>

extends AutowiredElementResolver
implements InstanceSupplier<T>
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.support.InstanceSupplier, org.springframework.util.function.ThrowingSupplier, java.util.function.Supplier
Type Parameters
<T>
the type of instance supplied by this supplier
Imports
java.lang.reflect.Constructor, .Executable, .Method, .Modifier, .Parameter, java.util.Arrays, .HashSet, .LinkedHashSet, .Map, .Set, java.util.stream.Collectors, org.springframework.aot.hint.ExecutableMode, org.springframework.beans.BeanInstantiationException, .BeanUtils, .BeansException, .TypeConverter, org.springframework.beans.factory.BeanFactory, .UnsatisfiedDependencyException, org.springframework.beans.factory.config.ConfigurableBeanFactory, .ConstructorArgumentValues, .ConstructorArgumentValues.ValueHolder, .DependencyDescriptor, org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory, .BeanDefinitionValueResolver, .InstanceSupplier, .RegisteredBean, .RootBeanDefinition, .SimpleInstantiationStrategy, org.springframework.core.MethodParameter, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils, .ReflectionUtils, org.springframework.util.function.ThrowingBiFunction, .ThrowingFunction, .ThrowingSupplier

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:

Generator callbacks handle checked exceptions so that the caller does not have to deal with them.
Authors
Phillip Webb, Stephane Nicoll
Since
6.0
See Also
AutowiredArguments

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv abstract static class
private static class
BeanInstanceSupplier.FactoryMethodLookup

Performs lookup of the factory Method.

Field Summary

Modifier and TypeField and Description
private final ThrowingBiFunction<RegisteredBean, AutowiredArguments, T>
private final BeanInstanceSupplier.ExecutableLookup
private final String[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private Object
public static <
the type of instance supplied
T
>
BeanInstanceSupplier<T>

Returns:

a new BeanInstanceSupplier instance
forConstructor
(Class<?>...
the constructor parameter types
parameterTypes
)

Create a BeanInstanceSupplier that resolves arguments for the specified bean constructor.

public static <
the type of instance supplied
T
>
BeanInstanceSupplier<T>

Returns:

a new BeanInstanceSupplier instance
forFactoryMethod
(Class<?>
the class that declares the factory method
declaringClass
,
String
the factory method name
methodName
,
Class<?>...
the factory method parameter types
parameterTypes
)

Create a new BeanInstanceSupplier that resolves arguments for the specified factory method.

public T
get(RegisteredBean
the registered bean requesting the instance
registeredBean
)

Implements org.springframework.beans.factory.support.InstanceSupplier.get.

Get the supplied instance.

public Method
getFactoryMethod()

Overrides default org.springframework.beans.factory.support.InstanceSupplier.getFactoryMethod.

Return the factory method that this supplier uses to create the instance, or null if it is not known or this supplier uses another means.

private Object
pack-priv BeanInstanceSupplier.ExecutableLookup
private MethodParameter
getMethodParameter(Executable executable, int index)

private T
instantiate(ConfigurableBeanFactory beanFactory, Executable executable, Object[] args)

private Object
instantiate(Constructor<?> constructor, Object[] args)

private Object
instantiate(ConfigurableBeanFactory beanFactory, Method method, Object[] args)

private T
invokeBeanSupplier(Executable executable, ThrowingSupplier<T> beanSupplier)

pack-priv AutowiredArguments

Returns:

the resolved constructor or factory method arguments
resolveArguments
(RegisteredBean
the registered bean
registeredBean
)

Resolve arguments for the specified registered bean.

private AutowiredArguments
resolveArguments(RegisteredBean registeredBean, Executable executable)

private ConstructorArgumentValues.ValueHolder
private ConstructorArgumentValues.ValueHolder[]
resolveArgumentValues(RegisteredBean registeredBean, Executable executable)

private Object
resolveAutowiredArgument(RegisteredBean registeredBean, DependencyDescriptor descriptor, ConstructorArgumentValues.ValueHolder argumentValue, Set<String> autowiredBeanNames)

private ConstructorArgumentValues
private static String
toCommaSeparatedNames(Class<?>... parameterTypes)

public BeanInstanceSupplier<T>

Returns:

a new BeanInstanceSupplier instance with the specified generator
withGenerator
(ThrowingBiFunction<RegisteredBean, AutowiredArguments, T>
a ThrowingBiFunction that uses the RegisteredBean and resolved AutowiredArguments to instantiate the underlying bean
generator
)

Return a new BeanInstanceSupplier instance that uses the specified generator bi-function to instantiate the underlying bean.

public BeanInstanceSupplier<T>

Returns:

a new BeanInstanceSupplier instance with the specified generator
withGenerator
(ThrowingFunction<RegisteredBean, T>
a ThrowingFunction that uses the RegisteredBean to instantiate the underlying bean
generator
)

Return a new BeanInstanceSupplier instance that uses the specified generator function to instantiate the underlying bean.

public BeanInstanceSupplier<T>

Returns:

a new BeanInstanceSupplier instance with the specified generator
withGenerator
(ThrowingSupplier<T>
a ThrowingSupplier to instantiate the underlying bean
generator
)
Deprecated for removal since 6.0.11. in favor of withGenerator(ThrowingFunction)

Return a new BeanInstanceSupplier instance that uses the specified generator supplier to instantiate the underlying bean.

public BeanInstanceSupplier<T>

Returns:

a new BeanInstanceSupplier instance that uses the shortcuts
withShortcuts
(String...
the bean names to use as shortcuts (aligned with the constructor or factory method parameters)
beanNames
)

Return a new BeanInstanceSupplier instance that uses direct bean name injection shortcuts for specific parameters.

Inherited from org.springframework.beans.factory.aot.AutowiredElementResolver:
registerDependentBeans

Field Detail

generatorback to summary
private final ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generator
Annotations
@Nullable
lookupback to summary
private final BeanInstanceSupplier.ExecutableLookup lookup
shortcutsback to summary
private final String[] shortcuts
Annotations
@Nullable

Constructor Detail

BeanInstanceSupplierback to summary
private BeanInstanceSupplier(BeanInstanceSupplier.ExecutableLookup lookup, ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generator, String[] shortcuts)

Method Detail

createInstanceback to summary
private Object createInstance(Class<?> clazz) throws Exception
forConstructorback to summary
public static <T> BeanInstanceSupplier<T> forConstructor(Class<?>... parameterTypes)

Create a BeanInstanceSupplier that resolves arguments for the specified bean constructor.

Parameters
<T>
the type of instance supplied
parameterTypes:Class<?>[]

the constructor parameter types

Returns:BeanInstanceSupplier<T>

a new BeanInstanceSupplier instance

forFactoryMethodback to summary
public static <T> BeanInstanceSupplier<T> forFactoryMethod(Class<?> declaringClass, String methodName, Class<?>... parameterTypes)

Create a new BeanInstanceSupplier that resolves arguments for the specified factory method.

Parameters
<T>
the type of instance supplied
declaringClass:Class<?>

the class that declares the factory method

methodName:String

the factory method name

parameterTypes:Class<?>[]

the factory method parameter types

Returns:BeanInstanceSupplier<T>

a new BeanInstanceSupplier instance

getback to summary
public T get(RegisteredBean registeredBean) throws Exception

Implements org.springframework.beans.factory.support.InstanceSupplier.get.

Doc from org.springframework.beans.factory.support.InstanceSupplier.get.

Get the supplied instance.

Parameters
registeredBean:RegisteredBean

the registered bean requesting the instance

Returns:T

the supplied instance

Annotations
@Override
Exceptions
Exception:
on error
getFactoryMethodback to summary
public Method getFactoryMethod()

Overrides default org.springframework.beans.factory.support.InstanceSupplier.getFactoryMethod.

Doc from org.springframework.beans.factory.support.InstanceSupplier.getFactoryMethod.

Return the factory method that this supplier uses to create the instance, or null if it is not known or this supplier uses another means.

Returns:Method

the factory method used to create the instance, or null

Annotations
@Nullable
@Override
getFactoryMethodTargetback to summary
private Object getFactoryMethodTarget(BeanFactory beanFactory, Method method)
Annotations
@Nullable
getLookupback to summary
pack-priv BeanInstanceSupplier.ExecutableLookup getLookup()
getMethodParameterback to summary
private MethodParameter getMethodParameter(Executable executable, int index)
instantiateback to summary
private T instantiate(ConfigurableBeanFactory beanFactory, Executable executable, Object[] args)
Annotations
@SuppressWarnings:unchecked
instantiateback to summary
private Object instantiate(Constructor<?> constructor, Object[] args) throws Exception
instantiateback to summary
private Object instantiate(ConfigurableBeanFactory beanFactory, Method method, Object[] args) throws Exception
invokeBeanSupplierback to summary
private T invokeBeanSupplier(Executable executable, ThrowingSupplier<T> beanSupplier)
resolveArgumentsback to summary
pack-priv AutowiredArguments resolveArguments(RegisteredBean registeredBean)

Resolve arguments for the specified registered bean.

Parameters
registeredBean:RegisteredBean

the registered bean

Returns:AutowiredArguments

the resolved constructor or factory method arguments

resolveArgumentsback to summary
private AutowiredArguments resolveArguments(RegisteredBean registeredBean, Executable executable)
resolveArgumentValueback to summary
private ConstructorArgumentValues.ValueHolder resolveArgumentValue(BeanDefinitionValueResolver resolver, ConstructorArgumentValues.ValueHolder valueHolder)
resolveArgumentValuesback to summary
private ConstructorArgumentValues.ValueHolder[] resolveArgumentValues(RegisteredBean registeredBean, Executable executable)
resolveAutowiredArgumentback to summary
private Object resolveAutowiredArgument(RegisteredBean registeredBean, DependencyDescriptor descriptor, ConstructorArgumentValues.ValueHolder argumentValue, Set<String> autowiredBeanNames)
Annotations
@Nullable
resolveConstructorArgumentsback to summary
private ConstructorArgumentValues resolveConstructorArguments(BeanDefinitionValueResolver valueResolver, ConstructorArgumentValues constructorArguments)
toCommaSeparatedNamesback to summary
private static String toCommaSeparatedNames(Class<?>... parameterTypes)
withGeneratorback to summary
public BeanInstanceSupplier<T> withGenerator(ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generator)

Return a new BeanInstanceSupplier instance that uses the specified generator bi-function to instantiate the underlying bean.

Parameters
generator:ThrowingBiFunction<RegisteredBean, AutowiredArguments, T>

a ThrowingBiFunction that uses the RegisteredBean and resolved AutowiredArguments to instantiate the underlying bean

Returns:BeanInstanceSupplier<T>

a new BeanInstanceSupplier instance with the specified generator

withGeneratorback to summary
public BeanInstanceSupplier<T> withGenerator(ThrowingFunction<RegisteredBean, T> generator)

Return a new BeanInstanceSupplier instance that uses the specified generator function to instantiate the underlying bean.

Parameters
generator:ThrowingFunction<RegisteredBean, T>

a ThrowingFunction that uses the RegisteredBean to instantiate the underlying bean

Returns:BeanInstanceSupplier<T>

a new BeanInstanceSupplier instance with the specified generator

withGeneratorback to summary
public BeanInstanceSupplier<T> withGenerator(ThrowingSupplier<T> generator)

Deprecated

for removal since 6.0.11.

in favor of withGenerator(ThrowingFunction)

Return a new BeanInstanceSupplier instance that uses the specified generator supplier to instantiate the underlying bean.

Parameters
generator:ThrowingSupplier<T>

a ThrowingSupplier to instantiate the underlying bean

Returns:BeanInstanceSupplier<T>

a new BeanInstanceSupplier instance with the specified generator

Annotations
@Deprecated
since:6.0.11
forRemoval:true
withShortcutsback to summary
public BeanInstanceSupplier<T> withShortcuts(String... beanNames)

Return a new BeanInstanceSupplier instance that uses direct bean name injection shortcuts for specific parameters.

Parameters
beanNames:String[]

the bean names to use as shortcuts (aligned with the constructor or factory method parameters)

Returns:BeanInstanceSupplier<T>

a new BeanInstanceSupplier instance that uses the shortcuts

org.springframework.beans.factory.aot back to summary

private Class BeanInstanceSupplier.ConstructorLookup

extends ExecutableLookup
Class Inheritance

Performs lookup of the Constructor.

Field Summary

Modifier and TypeField and Description
private final Class<?>[]

Constructor Summary

AccessConstructor and Description
pack-priv
ConstructorLookup(Class<?>[] parameterTypes)

Method Summary

Modifier and TypeMethod and Description
public Executable
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

parameterTypesback to summary
private final Class<?>[] parameterTypes

Constructor Detail

ConstructorLookupback to summary
pack-priv ConstructorLookup(Class<?>[] parameterTypes)

Method Detail

getback to summary
public Executable get(RegisteredBean registeredBean)

Implements abstract org.springframework.beans.factory.aot.BeanInstanceSupplier.ExecutableLookup.get.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.beans.factory.aot back to summary

pack-priv abstract Class BeanInstanceSupplier.ExecutableLookup

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.aot.BeanInstanceSupplier.ExecutableLookup
Known Direct Subclasses
org.springframework.beans.factory.aot.BeanInstanceSupplier.ConstructorLookup, org.springframework.beans.factory.aot.BeanInstanceSupplier.FactoryMethodLookup

Performs lookup of the Executable.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract Executable
get(RegisteredBean registeredBean)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ExecutableLookupback to summary
pack-priv ExecutableLookup()

Method Detail

getback to summary
pack-priv abstract Executable get(RegisteredBean registeredBean)
org.springframework.beans.factory.aot back to summary

private Class BeanInstanceSupplier.FactoryMethodLookup

extends ExecutableLookup
Class Inheritance

Performs lookup of the factory Method.

Field Summary

Modifier and TypeField and Description
private final Class<?>
private final String
private final Class<?>[]

Constructor Summary

AccessConstructor and Description
pack-priv
FactoryMethodLookup(Class<?> declaringClass, String methodName, Class<?>[] parameterTypes)

Method Summary

Modifier and TypeMethod and Description
public Executable
pack-priv Method
get()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Field Detail

declaringClassback to summary
private final Class<?> declaringClass
methodNameback to summary
private final String methodName
parameterTypesback to summary
private final Class<?>[] parameterTypes

Constructor Detail

FactoryMethodLookupback to summary
pack-priv FactoryMethodLookup(Class<?> declaringClass, String methodName, Class<?>[] parameterTypes)

Method Detail

getback to summary
public Executable get(RegisteredBean registeredBean)

Implements abstract org.springframework.beans.factory.aot.BeanInstanceSupplier.ExecutableLookup.get.

Annotations
@Override
getback to summary
pack-priv Method get()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override