public class SpringApplicationContextLoader
extends AbstractContextLoader
ContextLoader
that can be used to test Spring Boot applications (those that
normally startup using SpringApplication
). 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 @ActiveProfiles
are provided in the test class they will be used to
create the application context.
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. |
ApplicationContext |
loadContext(MergedContextConfiguration mergedConfig) |
ApplicationContext |
loadContext(String... locations) |
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception
Exception
protected SpringApplication getSpringApplication()
SpringApplication
instance. You can
override this method to add custom behaviourSpringApplication
instanceprotected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
AnnotationConfigContextLoaderUtils#detectDefaultConfigurationClasses
.declaringClass
- the test class that declared @ContextConfiguration
null
AnnotationConfigContextLoaderUtils
public ApplicationContext loadContext(String... locations) throws Exception
Exception
protected String getResourceSuffix()
Copyright © 2014. All rights reserved.