public class SpringBootContextLoader
extends org.springframework.test.context.support.AbstractContextLoader
ContextLoader that can be used to test Spring Boot applications (those that
normally startup using SpringApplication). Although this loader can be used
directly, most test will instead want to use it with
@SpringBootTest.
The loader supports both standard MergedContextConfiguration as well as
WebMergedContextConfiguration. If WebMergedContextConfiguration is used
the context will either use a mock servlet environment, or start the full embedded web
server.
If @ActiveProfiles are provided in the test class they will be used to create
the application context.
SpringBootTest| Constructor and Description |
|---|
SpringBootContextLoader() |
| Modifier and Type | Method and Description |
|---|---|
protected Class<?>[] |
detectDefaultConfigurationClasses(Class<?> declaringClass)
Detect the default configuration classes for the supplied test class.
|
protected String[] |
getArgs(org.springframework.test.context.MergedContextConfiguration config)
Return the application arguments to use.
|
protected org.springframework.core.env.ConfigurableEnvironment |
getEnvironment()
Builds a new
ConfigurableEnvironment instance. |
protected List<org.springframework.context.ApplicationContextInitializer<?>> |
getInitializers(org.springframework.test.context.MergedContextConfiguration config,
SpringApplication application)
Return the
initializers that will be applied
to the context. |
protected String[] |
getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config) |
protected String |
getResourceSuffix() |
protected String[] |
getResourceSuffixes() |
protected SpringApplication |
getSpringApplication()
Builds new
SpringApplication instance. |
org.springframework.context.ApplicationContext |
loadContext(org.springframework.test.context.MergedContextConfiguration config) |
org.springframework.context.ApplicationContext |
loadContext(String... locations) |
void |
processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes) |
public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration config)
throws Exception
Exceptionprotected SpringApplication getSpringApplication()
SpringApplication instance. You can
override this method to add custom behaviorSpringApplication instanceprotected org.springframework.core.env.ConfigurableEnvironment getEnvironment()
ConfigurableEnvironment instance. You can override this method
to return something other than StandardEnvironment if necessary.ConfigurableEnvironment instanceprotected String[] getArgs(org.springframework.test.context.MergedContextConfiguration config)
config - the source context configurationSpringApplication.run(String...)protected String[] getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config)
protected List<org.springframework.context.ApplicationContextInitializer<?>> getInitializers(org.springframework.test.context.MergedContextConfiguration config, SpringApplication application)
initializers that will be applied
to the context. By default this method will adapt context
customizers, add application
initializers and add
initializers
specified on the test.config - the source context configurationapplication - the application instancepublic void processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
processContextConfiguration in interface org.springframework.test.context.SmartContextLoaderprocessContextConfiguration in class org.springframework.test.context.support.AbstractContextLoaderprotected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(java.lang.Class<?>).declaringClass - the test class that declared @ContextConfigurationnullAnnotationConfigContextLoaderUtilspublic org.springframework.context.ApplicationContext loadContext(String... locations) throws Exception
Exceptionprotected String[] getResourceSuffixes()
getResourceSuffixes in class org.springframework.test.context.support.AbstractContextLoaderprotected String getResourceSuffix()
getResourceSuffix in class org.springframework.test.context.support.AbstractContextLoaderCopyright © 2019 Pivotal Software, Inc.. All rights reserved.