Package org.springframework.boot
Class DefaultBootstrapContext
java.lang.Object
org.springframework.boot.DefaultBootstrapContext
- All Implemented Interfaces:
BootstrapContext,BootstrapRegistry,ConfigurableBootstrapContext
Default
ConfigurableBootstrapContext implementation.- Since:
- 2.4.0
- Author:
- Phillip Webb
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.boot.BootstrapRegistry
BootstrapRegistry.InstanceSupplier<T>, BootstrapRegistry.Scope -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd anApplicationListenerthat will be called with aBootstrapContextClosedEventwhen theBootstrapContextis closed and theApplicationContexthas been prepared.voidclose(ConfigurableApplicationContext applicationContext) Method to be called whenBootstrapContextis closed and theApplicationContextis prepared.<T> TReturn an instance from the context if the type has been registered.<T> TReturn an instance from the context if the type has been registered.<T> TgetOrElseSupply(Class<T> type, Supplier<T> other) Return an instance from the context if the type has been registered.<T,X extends Throwable>
TgetOrElseThrow(Class<T> type, Supplier<? extends X> exceptionSupplier) Return an instance from the context if the type has been registered.getRegisteredInstanceSupplier(Class<T> type) Return any existingBootstrapRegistry.InstanceSupplierfor the given type.<T> booleanisRegistered(Class<T> type) Return if a registration exists for the given type.<T> voidregister(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier) Register a specific type with the registry.<T> voidregisterIfAbsent(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier) Register a specific type with the registry if one is not already present.
-
Constructor Details
-
DefaultBootstrapContext
public DefaultBootstrapContext()
-
-
Method Details
-
register
Description copied from interface:BootstrapRegistryRegister a specific type with the registry. If the specified type has already been registered and has not been obtained as asingleton, it will be replaced.- Specified by:
registerin interfaceBootstrapRegistry- Type Parameters:
T- the instance type- Parameters:
type- the instance typeinstanceSupplier- the instance supplier
-
registerIfAbsent
public <T> void registerIfAbsent(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier) Description copied from interface:BootstrapRegistryRegister a specific type with the registry if one is not already present.- Specified by:
registerIfAbsentin interfaceBootstrapRegistry- Type Parameters:
T- the instance type- Parameters:
type- the instance typeinstanceSupplier- the instance supplier
-
isRegistered
Description copied from interface:BootstrapRegistryReturn if a registration exists for the given type.- Specified by:
isRegisteredin interfaceBootstrapContext- Specified by:
isRegisteredin interfaceBootstrapRegistry- Type Parameters:
T- the instance type- Parameters:
type- the instance type- Returns:
trueif the type has already been registered
-
getRegisteredInstanceSupplier
Description copied from interface:BootstrapRegistryReturn any existingBootstrapRegistry.InstanceSupplierfor the given type.- Specified by:
getRegisteredInstanceSupplierin interfaceBootstrapRegistry- Type Parameters:
T- the instance type- Parameters:
type- the instance type- Returns:
- the registered
BootstrapRegistry.InstanceSupplierornull
-
addCloseListener
Description copied from interface:BootstrapRegistryAdd anApplicationListenerthat will be called with aBootstrapContextClosedEventwhen theBootstrapContextis closed and theApplicationContexthas been prepared.- Specified by:
addCloseListenerin interfaceBootstrapRegistry- Parameters:
listener- the listener to add
-
get
Description copied from interface:BootstrapContextReturn an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.- Specified by:
getin interfaceBootstrapContext- Type Parameters:
T- the instance type- Parameters:
type- the instance type- Returns:
- the instance managed by the context
- Throws:
IllegalStateException- if the type has not been registered
-
getOrElse
Description copied from interface:BootstrapContextReturn an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.- Specified by:
getOrElsein interfaceBootstrapContext- Type Parameters:
T- the instance type- Parameters:
type- the instance typeother- the instance to use if the type has not been registered- Returns:
- the instance
-
getOrElseSupply
Description copied from interface:BootstrapContextReturn an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.- Specified by:
getOrElseSupplyin interfaceBootstrapContext- Type Parameters:
T- the instance type- Parameters:
type- the instance typeother- a supplier for the instance to use if the type has not been registered- Returns:
- the instance
-
getOrElseThrow
public <T,X extends Throwable> T getOrElseThrow(Class<T> type, Supplier<? extends X> exceptionSupplier) throws X Description copied from interface:BootstrapContextReturn an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.- Specified by:
getOrElseThrowin interfaceBootstrapContext- Type Parameters:
T- the instance typeX- the exception to throw if the type is not registered- Parameters:
type- the instance typeexceptionSupplier- the supplier which will return the exception to be thrown- Returns:
- the instance managed by the context
- Throws:
X- if the type has not been registered
-
close
Method to be called whenBootstrapContextis closed and theApplicationContextis prepared.- Parameters:
applicationContext- the prepared context
-