Class SpringBootContextLoader
java.lang.Object
org.springframework.test.context.support.AbstractContextLoader
org.springframework.boot.test.context.SpringBootContextLoader
- All Implemented Interfaces:
- AotContextLoader,- 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 SummaryConstructors
- 
Method SummaryModifier 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 mergedConfig, SpringApplication application) Return theinitializersthat will be applied to the context.protected String[]getInlinedProperties(MergedContextConfiguration mergedConfig) protected Stringprotected String[]protected SpringApplicationBuilds newSpringApplicationinstance.loadContext(MergedContextConfiguration mergedConfig) loadContextForAotProcessing(MergedContextConfiguration mergedConfig) loadContextForAotRuntime(MergedContextConfiguration mergedConfig, ApplicationContextInitializer<ConfigurableApplicationContext> initializer) voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes) Methods inherited from class org.springframework.test.context.support.AbstractContextLoadercustomizeContext, generateDefaultLocations, isGenerateDefaultLocations, modifyLocations, prepareContext, processLocationsMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.test.context.SmartContextLoaderloadContext, processLocations
- 
Constructor Details- 
SpringBootContextLoaderpublic SpringBootContextLoader()
 
- 
- 
Method Details- 
loadContext- Specified by:
- loadContextin interface- SmartContextLoader
- Throws:
- Exception
 
- 
loadContextForAotProcessingpublic ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception - Specified by:
- loadContextForAotProcessingin interface- AotContextLoader
- Throws:
- Exception
 
- 
loadContextForAotRuntimepublic ApplicationContext loadContextForAotRuntime(MergedContextConfiguration mergedConfig, ApplicationContextInitializer<ConfigurableApplicationContext> initializer) throws Exception - Specified by:
- loadContextForAotRuntimein interface- AotContextLoader
- Throws:
- Exception
 
- 
getSpringApplicationBuilds newSpringApplicationinstance. This method is only called when amainmethod isn't being used to create theSpringApplication.- Returns:
- a SpringApplicationinstance
 
- 
getEnvironmentReturns theConfigurableEnvironmentinstance that should be applied toSpringApplicationornullto use the default. You can override this method if you need a custom environment.- Returns:
- a ConfigurableEnvironmentinstance
 
- 
getInlinedProperties
- 
getInitializersprotected List<ApplicationContextInitializer<?>> getInitializers(MergedContextConfiguration mergedConfig, 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:
- mergedConfig- the source context configuration
- application- the application instance
- Returns:
- the initializers to apply
- Since:
- 2.0.0
 
- 
processContextConfiguration- Specified by:
- processContextConfigurationin interface- SmartContextLoader
- Overrides:
- processContextConfigurationin class- AbstractContextLoader
 
- 
detectDefaultConfigurationClassesDetect 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:
 
- 
getResourceSuffixes- Overrides:
- getResourceSuffixesin class- AbstractContextLoader
 
- 
getResourceSuffix- Specified by:
- getResourceSuffixin class- AbstractContextLoader
 
 
-