public class SpringApplicationContextLoader
extends org.springframework.test.context.support.AbstractContextLoader
ContextLoader
that can be used to test Spring Boot applications (those that
normally startup using SpringApplication
). Normally never starts an embedded
web server, but detects the @WebAppConfiguration
annotation
on the test class and only creates a web application context if it is present. Non-web
features, like a repository layer, can be tested cleanly by simply not marking
the test class @WebAppConfiguration
.
If you want to start a web server, mark the test class as
@WebAppConfiguration @IntegrationTest
. This is useful for testing HTTP
endpoints using TestRestTemplate
(for instance), especially since you can
@Autowired
application context components into your test case to see the
internal effects of HTTP requests directly.
If @ActiveProfiles
are provided in the test class they will be used to
create the application context.
IntegrationTest
Constructor and Description |
---|
SpringApplicationContextLoader() |
Modifier and Type | Method and Description |
---|---|
protected Class<?>[] |
detectDefaultConfigurationClasses(Class<?> declaringClass)
Detect the default configuration classes for the supplied test class.
|
protected String |
getResourceSuffix() |
protected SpringApplication |
getSpringApplication()
Builds new
SpringApplication instance. |
org.springframework.context.ApplicationContext |
loadContext(org.springframework.test.context.MergedContextConfiguration mergedConfig) |
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 mergedConfig) throws Exception
Exception
public void processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
processContextConfiguration
in interface org.springframework.test.context.SmartContextLoader
processContextConfiguration
in class org.springframework.test.context.support.AbstractContextLoader
protected SpringApplication getSpringApplication()
SpringApplication
instance. You can
override this method to add custom behaviourSpringApplication
instanceprotected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(java.lang.Class<?>)
.declaringClass
- the test class that declared @ContextConfiguration
null
AnnotationConfigContextLoaderUtils
public org.springframework.context.ApplicationContext loadContext(String... locations) throws Exception
Exception
protected String getResourceSuffix()
getResourceSuffix
in class org.springframework.test.context.support.AbstractContextLoader
Copyright © 2014 Pivotal Software, Inc.. All rights reserved.