public final class WebApplicationContextRunner extends Object
ApplicationContext runner for a Servlet
based ConfigurableWebApplicationContext.
See AbstractApplicationContextRunner for details.
| Constructor and Description |
|---|
WebApplicationContextRunner()
Create a new
WebApplicationContextRunner instance using an
AnnotationConfigWebApplicationContext with a MockServletContext as
the underlying source. |
WebApplicationContextRunner(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory)
Create a new
WebApplicationContextRunner instance using the specified
contextFactory as the underlying source. |
| Modifier and Type | Method and Description |
|---|---|
protected WebApplicationContextRunner |
newInstance(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory,
TestPropertyValues environmentProperties,
TestPropertyValues systemProperties,
ClassLoader classLoader,
org.springframework.context.ApplicationContext parent,
List<Configurations> configurations) |
SELF |
run(ContextConsumer<? super A> consumer)
Create and refresh a new
ApplicationContext based on the current state of
this loader. |
SELF |
withClassLoader(ClassLoader classLoader)
Customize the
ClassLoader that the ApplicationContext should use. |
SELF |
withConfiguration(Configurations configurations)
Register the specified configuration classes with the
ApplicationContext. |
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. |
SELF |
withParent(org.springframework.context.ApplicationContext parent)
Configure the
parent of the ApplicationContext. |
SELF |
withPropertyValues(String... pairs)
Add the specified
Environment property pairs. |
SELF |
withSystemProperties(String... pairs)
Add the specified
System property pairs. |
SELF |
withUserConfiguration(Class<?>... configurationClasses)
Register the specified user configuration classes with the
ApplicationContext. |
public WebApplicationContextRunner()
WebApplicationContextRunner instance using an
AnnotationConfigWebApplicationContext with a MockServletContext as
the underlying source.withMockServletContext(Supplier)public WebApplicationContextRunner(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory)
WebApplicationContextRunner instance using the specified
contextFactory as the underlying source.contextFactory - a supplier that returns a new instance on each callprotected WebApplicationContextRunner newInstance(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader, org.springframework.context.ApplicationContext parent, List<Configurations> configurations)
public static Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> withMockServletContext(Supplier<org.springframework.web.context.ConfigurableWebApplicationContext> contextFactory)
contextFactory to set a MockServletContext
on each newly created WebApplicationContext.contextFactory - the context factory to decorateMockServletContextpublic SELF withPropertyValues(String... pairs)
Environment property pairs. Key-value pairs can be
specified with colon (":") or equals ("=") separators. Override matching keys that
might have been specified previously.pairs - the key-value pairs for properties that need to be added to the
environmentTestPropertyValues,
withSystemProperties(String...)public SELF withSystemProperties(String... pairs)
System property pairs. Key-value pairs can be specified
with colon (":") or equals ("=") separators. System properties are added before the
context is run and restored when the context is
closed.pairs - the key-value pairs for properties that need to be added to the systemTestPropertyValues,
withSystemProperties(String...)public SELF withClassLoader(ClassLoader classLoader)
ClassLoader that the ApplicationContext should use.
Customizing the ClassLoader is an effective manner to hide resources from
the classpath.classLoader - the classloader to use (can be null to use the default)HidePackagesClassLoaderpublic SELF withParent(org.springframework.context.ApplicationContext parent)
parent of the ApplicationContext.parent - the parentpublic SELF withUserConfiguration(Class<?>... configurationClasses)
ApplicationContext.configurationClasses - the user configuration classes to addpublic SELF withConfiguration(Configurations configurations)
ApplicationContext.configurations - the configurations to addpublic SELF run(ContextConsumer<? super A> consumer)
ApplicationContext based on the current state of
this loader. The context is consumed by the specified consumer and closed
upon completion.consumer - the consumer of the created ApplicationContextCopyright © 2017 Pivotal Software, Inc.. All rights reserved.