org.springframework.boot

Class DefaultBootstrapContext

  • java.lang.Object
    • org.springframework.boot.DefaultBootstrapContext
    • Constructor Detail

      • DefaultBootstrapContext

        public DefaultBootstrapContext()
    • Method Detail

      • register

        public <T> void register(java.lang.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, but not get obtained, 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(java.lang.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(java.lang.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
      • get

        public <T> T get(java.lang.Class<T> type)
                  throws java.lang.IllegalStateException
        Description copied from interface: BootstrapContext
        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.
        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:
        java.lang.IllegalStateException - if the type has not been registered
      • getOrElse

        public <T> T getOrElse(java.lang.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 it 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(java.lang.Class<T> type,
                                     java.util.function.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 it 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 java.lang.Throwable> T getOrElseThrow(java.lang.Class<T> type,
                                                                  java.util.function.Supplier<? extends X> exceptionSupplier)
                                                           throws X extends java.lang.Throwable
        Description copied from interface: BootstrapContext
        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.
        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
        X extends java.lang.Throwable
      • close

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