Class WebApplicationContextRunner

java.lang.Object
org.springframework.boot.test.context.runner.AbstractApplicationContextRunner<WebApplicationContextRunner,org.springframework.web.context.ConfigurableWebApplicationContext,AssertableWebApplicationContext>
org.springframework.boot.test.context.runner.WebApplicationContextRunner

public final class WebApplicationContextRunner extends AbstractApplicationContextRunner<WebApplicationContextRunner,org.springframework.web.context.ConfigurableWebApplicationContext,AssertableWebApplicationContext>
An ApplicationContext runner for a Servlet based ConfigurableWebApplicationContext.

See AbstractApplicationContextRunner for details.

Since:
2.0.0
  • Constructor Details

    • WebApplicationContextRunner

      public WebApplicationContextRunner()
      Create a new WebApplicationContextRunner instance using an AnnotationConfigServletWebApplicationContext with a MockServletContext as the underlying source.
      See Also:
    • WebApplicationContextRunner

      public WebApplicationContextRunner(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory)
      Create a new WebApplicationContextRunner instance using the specified contextFactory as the underlying source.
      Parameters:
      contextFactory - a supplier that returns a new instance on each call
  • Method Details

    • withMockServletContext

      public static Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> withMockServletContext(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory)
      Decorate the specified contextFactory to set a MockServletContext on each newly created WebApplicationContext.
      Parameters:
      contextFactory - the context factory to decorate
      Returns:
      an updated supplier that will set the MockServletContext