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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add anApplicationListener
that will be called with aBootstrapContextClosedEvent
when theBootstrapContext
is closed and theApplicationContext
has been prepared.void
close
(ConfigurableApplicationContext applicationContext) Method to be called whenBootstrapContext
is closed and theApplicationContext
is prepared.<T> T
Return an instance from the context if the type has been registered.<T> T
Return an instance from the context if the type has been registered.<T> T
getOrElseSupply
(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.InstanceSupplier
for the given type.<T> boolean
isRegistered
(Class<T> type) Return if a registration exists for the given type.<T> void
register
(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier) Register a specific type with the registry.<T> void
registerIfAbsent
(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:BootstrapRegistry
Register 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:
register
in 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:BootstrapRegistry
Register a specific type with the registry if one is not already present.- Specified by:
registerIfAbsent
in interfaceBootstrapRegistry
- Type Parameters:
T
- the instance type- Parameters:
type
- the instance typeinstanceSupplier
- the instance supplier
-
isRegistered
Description copied from interface:BootstrapRegistry
Return if a registration exists for the given type.- Specified by:
isRegistered
in interfaceBootstrapContext
- Specified by:
isRegistered
in interfaceBootstrapRegistry
- Type Parameters:
T
- the instance type- Parameters:
type
- the instance type- Returns:
true
if the type has already been registered
-
getRegisteredInstanceSupplier
Description copied from interface:BootstrapRegistry
Return any existingBootstrapRegistry.InstanceSupplier
for the given type.- Specified by:
getRegisteredInstanceSupplier
in interfaceBootstrapRegistry
- Type Parameters:
T
- the instance type- Parameters:
type
- the instance type- Returns:
- the registered
BootstrapRegistry.InstanceSupplier
ornull
-
addCloseListener
Description copied from interface:BootstrapRegistry
Add anApplicationListener
that will be called with aBootstrapContextClosedEvent
when theBootstrapContext
is closed and theApplicationContext
has been prepared.- Specified by:
addCloseListener
in interfaceBootstrapRegistry
- Parameters:
listener
- the listener to add
-
get
Description copied from interface:BootstrapContext
Return an instance from the context if the type has been registered. The instance will be created if it hasn't been accessed previously.- Specified by:
get
in 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:BootstrapContext
Return an instance from the context if the type has been registered. The instance will be created if it hasn't been accessed previously.- Specified by:
getOrElse
in 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:BootstrapContext
Return an instance from the context if the type has been registered. The instance will be created if it hasn't been accessed previously.- Specified by:
getOrElseSupply
in 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:BootstrapContext
Return an instance from the context if the type has been registered. The instance will be created if it hasn't been accessed previously.- Specified by:
getOrElseThrow
in 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 whenBootstrapContext
is closed and theApplicationContext
is prepared.- Parameters:
applicationContext
- the prepared context
-