Interface ApplicationContextFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ApplicationContextFactory
Strategy interface for creating the ConfigurableApplicationContext used by a SpringApplication. Created contexts should be returned in their default form, with the SpringApplication responsible for configuring and refreshing the context.
Since:
2.4.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    A default ApplicationContextFactory implementation that will create an appropriate context for the WebApplicationType.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable org.springframework.context.ConfigurableApplicationContext
    create(@Nullable WebApplicationType webApplicationType)
    Creates the application context for a SpringApplication, respecting the given webApplicationType.
    default @Nullable org.springframework.core.env.ConfigurableEnvironment
    createEnvironment(@Nullable WebApplicationType webApplicationType)
    Create a new Environment to be set on the created application context.
    default @Nullable Class<? extends org.springframework.core.env.ConfigurableEnvironment>
    getEnvironmentType(@Nullable WebApplicationType webApplicationType)
    Return the Environment type expected to be set on the created application context.
    of(Supplier<org.springframework.context.ConfigurableApplicationContext> supplier)
    Creates an ApplicationContextFactory that will create contexts by calling the given Supplier.
    ofContextClass(Class<? extends org.springframework.context.ConfigurableApplicationContext> contextClass)
    Creates an ApplicationContextFactory that will create contexts by instantiating the given contextClass through its primary constructor.
  • Field Details

  • Method Details

    • getEnvironmentType

      default @Nullable Class<? extends org.springframework.core.env.ConfigurableEnvironment> getEnvironmentType(@Nullable WebApplicationType webApplicationType)
      Return the Environment type expected to be set on the created application context. The result of this method can be used to convert an existing environment instance to the correct type.
      Parameters:
      webApplicationType - the web application type or null
      Returns:
      the expected application context type or null to use the default
      Since:
      2.6.14
    • createEnvironment

      default @Nullable org.springframework.core.env.ConfigurableEnvironment createEnvironment(@Nullable WebApplicationType webApplicationType)
      Create a new Environment to be set on the created application context. The result of this method must match the type returned by getEnvironmentType(WebApplicationType).
      Parameters:
      webApplicationType - the web application type or null
      Returns:
      an environment instance or null to use the default
      Since:
      2.6.14
    • create

      @Nullable org.springframework.context.ConfigurableApplicationContext create(@Nullable WebApplicationType webApplicationType)
      Creates the application context for a SpringApplication, respecting the given webApplicationType.
      Parameters:
      webApplicationType - the web application type
      Returns:
      the newly created application context
    • ofContextClass

      static ApplicationContextFactory ofContextClass(Class<? extends org.springframework.context.ConfigurableApplicationContext> contextClass)
      Creates an ApplicationContextFactory that will create contexts by instantiating the given contextClass through its primary constructor.
      Parameters:
      contextClass - the context class
      Returns:
      the factory that will instantiate the context class
      See Also:
      • BeanUtils.instantiateClass(Class)
    • of

      static ApplicationContextFactory of(Supplier<org.springframework.context.ConfigurableApplicationContext> supplier)
      Creates an ApplicationContextFactory that will create contexts by calling the given Supplier.
      Parameters:
      supplier - the context supplier, for example AnnotationConfigApplicationContext::new
      Returns:
      the factory that will instantiate the context class