Class DefaultBootstrapContext

java.lang.Object
org.springframework.boot.DefaultBootstrapContext
All Implemented Interfaces:
BootstrapContext, BootstrapRegistry, ConfigurableBootstrapContext

public class DefaultBootstrapContext extends Object implements ConfigurableBootstrapContext
Default ConfigurableBootstrapContext implementation.
Since:
2.4.0
Author:
Phillip Webb
  • Constructor Details

    • DefaultBootstrapContext

      public DefaultBootstrapContext()
  • Method Details

    • register

      public <T> void register(Class<T> type, BootstrapRegistry.InstanceSupplier<T> instanceSupplier)
      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 a singleton, it will be replaced.
      Specified by:
      register in interface BootstrapRegistry
      Type Parameters:
      T - the instance type
      Parameters:
      type - the instance type
      instanceSupplier - 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 interface BootstrapRegistry
      Type Parameters:
      T - the instance type
      Parameters:
      type - the instance type
      instanceSupplier - the instance supplier
    • isRegistered

      public <T> boolean isRegistered(Class<T> type)
      Description copied from interface: BootstrapRegistry
      Return if a registration exists for the given type.
      Specified by:
      isRegistered in interface BootstrapContext
      Specified by:
      isRegistered in interface BootstrapRegistry
      Type Parameters:
      T - the instance type
      Parameters:
      type - the instance type
      Returns:
      true if the type has already been registered
    • getRegisteredInstanceSupplier

      public <T> BootstrapRegistry.InstanceSupplier<T> getRegisteredInstanceSupplier(Class<T> type)
      Description copied from interface: BootstrapRegistry
      Return any existing BootstrapRegistry.InstanceSupplier for the given type.
      Specified by:
      getRegisteredInstanceSupplier in interface BootstrapRegistry
      Type Parameters:
      T - the instance type
      Parameters:
      type - the instance type
      Returns:
      the registered BootstrapRegistry.InstanceSupplier or null
    • addCloseListener

      public void addCloseListener(ApplicationListener<BootstrapContextClosedEvent> listener)
      Description copied from interface: BootstrapRegistry
      Add an ApplicationListener that will be called with a BootstrapContextClosedEvent when the BootstrapContext is closed and the ApplicationContext has been prepared.
      Specified by:
      addCloseListener in interface BootstrapRegistry
      Parameters:
      listener - the listener to add
    • get

      public <T> T get(Class<T> type) throws IllegalStateException
      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 interface BootstrapContext
      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

      public <T> T getOrElse(Class<T> type, T other)
      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 interface BootstrapContext
      Type Parameters:
      T - the instance type
      Parameters:
      type - the instance type
      other - the instance to use if the type has not been registered
      Returns:
      the instance
    • getOrElseSupply

      public <T> T getOrElseSupply(Class<T> type, Supplier<T> other)
      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 interface BootstrapContext
      Type Parameters:
      T - the instance type
      Parameters:
      type - the instance type
      other - 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 interface BootstrapContext
      Type Parameters:
      T - the instance type
      X - the exception to throw if the type is not registered
      Parameters:
      type - the instance type
      exceptionSupplier - 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

      public void close(ConfigurableApplicationContext applicationContext)
      Method to be called when BootstrapContext is closed and the ApplicationContext is prepared.
      Parameters:
      applicationContext - the prepared context