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 java.lang.Class<?>[] |
detectDefaultConfigurationClasses(java.lang.Class<?> declaringClass)
Detect the default configuration classes for the supplied test class.
|
protected org.springframework.core.env.ConfigurableEnvironment |
getEnvironment()
Returns the
ConfigurableEnvironment instance that should be applied to
SpringApplication or null to use the default. |
protected java.util.List<org.springframework.context.ApplicationContextInitializer<?>> |
getInitializers(org.springframework.test.context.MergedContextConfiguration config,
org.springframework.boot.SpringApplication application)
Return the
initializers that will be applied
to the context. |
protected java.lang.String[] |
getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config) |
protected java.lang.String |
getResourceSuffix() |
protected java.lang.String[] |
getResourceSuffixes() |
protected org.springframework.boot.SpringApplication |
getSpringApplication()
Builds new
SpringApplication instance. |
org.springframework.context.ApplicationContext |
loadContext(org.springframework.test.context.MergedContextConfiguration config) |
org.springframework.context.ApplicationContext |
loadContext(java.lang.String... locations) |
void |
processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes) |
public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration config)
throws java.lang.Exception
java.lang.Exceptionprotected org.springframework.boot.SpringApplication getSpringApplication()
SpringApplication instance. You can
override this method to add custom behaviorSpringApplication instanceprotected org.springframework.core.env.ConfigurableEnvironment getEnvironment()
ConfigurableEnvironment instance that should be applied to
SpringApplication or null to use the default. You can override this
method if you need a custom environment.ConfigurableEnvironment instanceprotected java.lang.String[] getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config)
protected java.util.List<org.springframework.context.ApplicationContextInitializer<?>> getInitializers(org.springframework.test.context.MergedContextConfiguration config,
org.springframework.boot.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 java.lang.Class<?>[] detectDefaultConfigurationClasses(java.lang.Class<?> declaringClass)
AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(java.lang.Class<?>).declaringClass - the test class that declared @ContextConfigurationnullAnnotationConfigContextLoaderUtilspublic org.springframework.context.ApplicationContext loadContext(java.lang.String... locations)
throws java.lang.Exception
java.lang.Exceptionprotected java.lang.String[] getResourceSuffixes()
getResourceSuffixes in class org.springframework.test.context.support.AbstractContextLoaderprotected java.lang.String getResourceSuffix()
getResourceSuffix in class org.springframework.test.context.support.AbstractContextLoader