Package org.springframework.boot
Interface BootstrapRegistry
- All Known Subinterfaces:
ConfigurableBootstrapContext
- All Known Implementing Classes:
DefaultBootstrapContext
public interface BootstrapRegistry
A simple object registry that is available during startup and
Environment
post-processing up to the point that the ApplicationContext is prepared.
Can be used to register instances that may be expensive to create, or need to be shared
before the ApplicationContext is available.
The registry uses Class as a key, meaning that only a single instance of a
given type can be stored.
The addCloseListener(ApplicationListener) method can be used to add a listener
that can perform actions when BootstrapContext has been closed and the
ApplicationContext is fully prepared. For example, an instance may choose to
register itself as a regular Spring bean so that it is available for the application to
use.
- Since:
- 2.4.0
- Author:
- Phillip Webb
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSupplier used to provide the actual instance when needed.static enumThe scope of an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd anApplicationListenerthat will be called with aBootstrapContextClosedEventwhen theBootstrapContextis closed and theApplicationContexthas been prepared.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.
-
Method Details
-
register
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.- Type Parameters:
T- the instance type- Parameters:
type- the instance typeinstanceSupplier- the instance supplier
-
registerIfAbsent
Register a specific type with the registry if one is not already present.- Type Parameters:
T- the instance type- Parameters:
type- the instance typeinstanceSupplier- the instance supplier
-
isRegistered
Return if a registration exists for the given type.- Type Parameters:
T- the instance type- Parameters:
type- the instance type- Returns:
trueif the type has already been registered
-
getRegisteredInstanceSupplier
Return any existingBootstrapRegistry.InstanceSupplierfor the given type.- Type Parameters:
T- the instance type- Parameters:
type- the instance type- Returns:
- the registered
BootstrapRegistry.InstanceSupplierornull
-
addCloseListener
Add anApplicationListenerthat will be called with aBootstrapContextClosedEventwhen theBootstrapContextis closed and theApplicationContexthas been prepared.- Parameters:
listener- the listener to add
-