org.springframework.boot

Interface BootstrapContext

  • All Known Subinterfaces:
    ConfigurableBootstrapContext
    All Known Implementing Classes:
    DefaultBootstrapContext


    public interface BootstrapContext
    A simple bootstrap context that is available during startup and Environment post-processing up to the point that the ApplicationContext is prepared.

    Provides lazy access to singletons that may be expensive to create, or need to be shared before the ApplicationContext is available.

    Since:
    2.4.0
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method and Description
      <T> T get(java.lang.Class<T> type)
      Return an instance from the context if the type has been registered.
      <T> T getOrElse(java.lang.Class<T> type, T other)
      Return an instance from the context if the type has been registered.
      <T> T getOrElseSupply(java.lang.Class<T> type, java.util.function.Supplier<T> other)
      Return an instance from the context if the type has been registered.
      <T,X extends java.lang.Throwable>
      T
      getOrElseThrow(java.lang.Class<T> type, java.util.function.Supplier<? extends X> exceptionSupplier)
      Return an instance from the context if the type has been registered.
      <T> boolean isRegistered(java.lang.Class<T> type)
      Return if a registration exists for the given type.
    • Method Detail

      • get

        <T> T get(java.lang.Class<T> type)
           throws java.lang.IllegalStateException
        Return an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.
        Type Parameters:
        T - the instance type
        Parameters:
        type - the instance type
        Returns:
        the instance managed by the context
        Throws:
        java.lang.IllegalStateException - if the type has not been registered
      • getOrElse

        <T> T getOrElse(java.lang.Class<T> type,
                        T other)
        Return an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.
        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

        <T> T getOrElseSupply(java.lang.Class<T> type,
                              java.util.function.Supplier<T> other)
        Return an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.
        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

        <T,X extends java.lang.Throwable> T getOrElseThrow(java.lang.Class<T> type,
                                                           java.util.function.Supplier<? extends X> exceptionSupplier)
                                                    throws X extends java.lang.Throwable
        Return an instance from the context if the type has been registered. The instance will be created it if it hasn't been accessed previously.
        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
        java.lang.IllegalStateException - if the type has not been registered
        X extends java.lang.Throwable
      • isRegistered

        <T> boolean isRegistered(java.lang.Class<T> type)
        Return if a registration exists for the given type.
        Type Parameters:
        T - the instance type
        Parameters:
        type - the instance type
        Returns:
        true if the type has already been registered