Class SpringBootContextLoader
java.lang.Object
org.springframework.test.context.support.AbstractContextLoader
org.springframework.boot.test.context.SpringBootContextLoader
- All Implemented Interfaces:
ContextLoader,SmartContextLoader
A
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.
- Since:
- 1.4.0
- Author:
- Dave Syer, Phillip Webb, Andy Wilkinson, Stephane Nicoll, Madhura Bhave, Scott Frederick
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?>[]detectDefaultConfigurationClasses(Class<?> declaringClass) Detect the default configuration classes for the supplied test class.protected ConfigurableEnvironmentReturns theConfigurableEnvironmentinstance that should be applied toSpringApplicationornullto use the default.protected List<ApplicationContextInitializer<?>>getInitializers(MergedContextConfiguration config, SpringApplication application) Return theinitializersthat will be applied to the context.protected String[]protected Stringprotected String[]protected SpringApplicationBuilds newSpringApplicationinstance.loadContext(String... locations) voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes) Methods inherited from class org.springframework.test.context.support.AbstractContextLoader
customizeContext, generateDefaultLocations, isGenerateDefaultLocations, modifyLocations, prepareContext, processLocations
-
Constructor Details
-
SpringBootContextLoader
public SpringBootContextLoader()
-
-
Method Details
-
loadContext
- Throws:
Exception
-
getSpringApplication
Builds newSpringApplicationinstance. You can override this method to add custom behavior- Returns:
SpringApplicationinstance
-
getEnvironment
Returns theConfigurableEnvironmentinstance that should be applied toSpringApplicationornullto use the default. You can override this method if you need a custom environment.- Returns:
- a
ConfigurableEnvironmentinstance
-
getInlinedProperties
-
getInitializers
protected List<ApplicationContextInitializer<?>> getInitializers(MergedContextConfiguration config, SpringApplication application) Return theinitializersthat will be applied to the context. By default this method will adaptcontext customizers, addapplication initializersand addinitializers specified on the test.- Parameters:
config- the source context configurationapplication- the application instance- Returns:
- the initializers to apply
- Since:
- 2.0.0
-
processContextConfiguration
- Specified by:
processContextConfigurationin interfaceSmartContextLoader- Overrides:
processContextConfigurationin classAbstractContextLoader
-
detectDefaultConfigurationClasses
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:
-
loadContext
- Throws:
Exception
-
getResourceSuffixes
- Overrides:
getResourceSuffixesin classAbstractContextLoader
-
getResourceSuffix
- Specified by:
getResourceSuffixin classAbstractContextLoader
-