public class SpringBootContextLoader extends 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() |
customizeContext, generateDefaultLocations, isGenerateDefaultLocations, modifyLocations, prepareContext, processLocations
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception
Exception
protected SpringApplication getSpringApplication()
SpringApplication
instance. You can
override this method to add custom behaviorSpringApplication
instanceprotected 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 String[] getInlinedProperties(MergedContextConfiguration config)
protected List<ApplicationContextInitializer<?>> getInitializers(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(ContextConfigurationAttributes configAttributes)
processContextConfiguration
in interface SmartContextLoader
processContextConfiguration
in class AbstractContextLoader
protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(java.lang.Class<?>)
.declaringClass
- the test class that declared @ContextConfiguration
null
AnnotationConfigContextLoaderUtils
public ApplicationContext loadContext(String... locations) throws Exception
Exception
protected String[] getResourceSuffixes()
getResourceSuffixes
in class AbstractContextLoader
protected String getResourceSuffix()
getResourceSuffix
in class AbstractContextLoader