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
AContextLoaderthat 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
MergedContextConfigurationas well asWebMergedContextConfiguration. IfWebMergedContextConfigurationis used the context will either use a mock servlet environment, or start the full embedded servlet container.If
@ActiveProfilesare 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 StringgetResourceSuffix()protected String[]getResourceSuffixes()protected org.springframework.boot.SpringApplicationgetSpringApplication()Builds newSpringApplicationinstance.org.springframework.context.ApplicationContextloadContext(String... locations)org.springframework.context.ApplicationContextloadContext(org.springframework.test.context.MergedContextConfiguration config)voidprocessContextConfiguration(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 newSpringApplicationinstance. You can override this method to add custom behavior- Returns:
SpringApplicationinstance
getInlinedProperties
protected String[] getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config)
processContextConfiguration
public void processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
- Specified by:
processContextConfigurationin interfaceorg.springframework.test.context.SmartContextLoader- Overrides:
processContextConfigurationin 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:
getResourceSuffixesin classorg.springframework.test.context.support.AbstractContextLoader
getResourceSuffix
protected String getResourceSuffix()
- Specified by:
getResourceSuffixin classorg.springframework.test.context.support.AbstractContextLoader