Class SpringBootContextLoader
- java.lang.Object
- org.springframework.test.context.support.AbstractContextLoader
- org.springframework.boot.test.context.SpringBootContextLoader
- All Implemented Interfaces:
org.springframework.test.context.ContextLoader
,org.springframework.test.context.SmartContextLoader
public class SpringBootContextLoader extends org.springframework.test.context.support.AbstractContextLoader
AContextLoader
that can be used to test Spring Boot applications (those that normally startup usingSpringApplication
). Although this loader can be used directly, most test will instead want to use it withSpringBootTest
.The loader supports both standard
MergedContextConfiguration
as well asWebMergedContextConfiguration
. IfWebMergedContextConfiguration
is used the context will either use a mock servlet environment, or start the full embedded servlet container.If
@ActiveProfiles
are provided in the test class they will be used to create the application context.- See Also:
SpringBootTest
Constructor Summary
Constructors Constructor Description SpringBootContextLoader()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Class<?>[]
detectDefaultConfigurationClasses(Class<?> declaringClass)
Detect the default configuration classes for the supplied test class.protected String[]
getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config)
protected String
getResourceSuffix()
protected String[]
getResourceSuffixes()
protected org.springframework.boot.SpringApplication
getSpringApplication()
Builds newSpringApplication
instance.org.springframework.context.ApplicationContext
loadContext(String... locations)
org.springframework.context.ApplicationContext
loadContext(org.springframework.test.context.MergedContextConfiguration config)
void
processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
Constructor Detail
SpringBootContextLoader
public SpringBootContextLoader()
Method Detail
loadContext
public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration config) throws Exception
- Throws:
Exception
getSpringApplication
protected org.springframework.boot.SpringApplication getSpringApplication()
Builds newSpringApplication
instance. You can override this method to add custom behavior- Returns:
SpringApplication
instance
getInlinedProperties
protected String[] getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config)
processContextConfiguration
public void processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
- Specified by:
processContextConfiguration
in interfaceorg.springframework.test.context.SmartContextLoader
- Overrides:
processContextConfiguration
in classorg.springframework.test.context.support.AbstractContextLoader
detectDefaultConfigurationClasses
protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
Detect the default configuration classes for the supplied test class. By default simply delegates toAnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(java.lang.Class<?>)
.- Parameters:
declaringClass
- the test class that declared@ContextConfiguration
- Returns:
- an array of default configuration classes, potentially empty but never
null
- See Also:
AnnotationConfigContextLoaderUtils
loadContext
public org.springframework.context.ApplicationContext loadContext(String... locations) throws Exception
- Throws:
Exception
getResourceSuffixes
protected String[] getResourceSuffixes()
- Overrides:
getResourceSuffixes
in classorg.springframework.test.context.support.AbstractContextLoader
getResourceSuffix
protected String getResourceSuffix()
- Specified by:
getResourceSuffix
in classorg.springframework.test.context.support.AbstractContextLoader