Package org.springframework.boot.util
Class Instantiator<T>
java.lang.Object
org.springframework.boot.util.Instantiator<T>
- Type Parameters:
T
- the type to instantiate
Simple factory used to instantiate objects by injecting available parameters.
- Since:
- 2.4.0
- Author:
- Phillip Webb, Scott Frederick
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback used to register available parameters.static interface
Strategy for handling a failure that occurs when instantiating a type. -
Constructor Summary
ConstructorDescriptionInstantiator
(Class<?> type, Consumer<Instantiator.AvailableParameters> availableParameters) Create a newInstantiator
instance for the given type.Instantiator
(Class<?> type, Consumer<Instantiator.AvailableParameters> availableParameters, Instantiator.FailureHandler failureHandler) Create a newInstantiator
instance for the given type. -
Method Summary
Modifier and TypeMethodDescription<A> A
Get an injectable argument instance for the given type.instantiate
(ClassLoader classLoader, String name) Instantiate the given set of class name, injecting constructor arguments as necessary.instantiate
(ClassLoader classLoader, Collection<String> names) Instantiate the given set of class name, injecting constructor arguments as necessary.instantiate
(String name) Instantiate the given set of class name, injecting constructor arguments as necessary.instantiate
(Collection<String> names) Instantiate the given set of class name, injecting constructor arguments as necessary.instantiateType
(Class<?> type) Instantiate the given class, injecting constructor arguments as necessary.instantiateTypes
(Collection<Class<?>> types) Instantiate the given set of classes, injecting constructor arguments as necessary.
-
Constructor Details
-
Instantiator
Create a newInstantiator
instance for the given type.- Parameters:
type
- the type to instantiateavailableParameters
- consumer used to register available parameters
-
Instantiator
public Instantiator(Class<?> type, Consumer<Instantiator.AvailableParameters> availableParameters, Instantiator.FailureHandler failureHandler) Create a newInstantiator
instance for the given type.- Parameters:
type
- the type to instantiateavailableParameters
- consumer used to register available parametersfailureHandler
- aInstantiator.FailureHandler
that will be called in case of failure when instantiating objects- Since:
- 2.7.0
-
-
Method Details
-
instantiate
Instantiate the given set of class name, injecting constructor arguments as necessary.- Parameters:
names
- the class names to instantiate- Returns:
- a list of instantiated instances
-
instantiate
Instantiate the given set of class name, injecting constructor arguments as necessary.- Parameters:
classLoader
- the source classloadernames
- the class names to instantiate- Returns:
- a list of instantiated instances
- Since:
- 2.4.8
-
instantiate
Instantiate the given set of class name, injecting constructor arguments as necessary.- Parameters:
name
- the class name to instantiate- Returns:
- an instantiated instance
- Since:
- 3.4.0
-
instantiate
Instantiate the given set of class name, injecting constructor arguments as necessary.- Parameters:
classLoader
- the source classloadername
- the class name to instantiate- Returns:
- an instantiated instance
- Since:
- 3.4.0
-
instantiateType
Instantiate the given class, injecting constructor arguments as necessary.- Parameters:
type
- the type to instantiate- Returns:
- an instantiated instance
- Since:
- 3.4.0
-
instantiateTypes
Instantiate the given set of classes, injecting constructor arguments as necessary.- Parameters:
types
- the types to instantiate- Returns:
- a list of instantiated instances
- Since:
- 2.4.8
-
getArg
Get an injectable argument instance for the given type. This method can be used when manually instantiating an object without reflection.- Type Parameters:
A
- the argument type- Parameters:
type
- the argument type- Returns:
- the argument to inject or
null
- Since:
- 3.4.0
-