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
-
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?>[]
detectDefaultConfigurationClasses
(Class<?> declaringClass) Detect the default configuration classes for the supplied test class.protected ConfigurableEnvironment
Returns theConfigurableEnvironment
instance that should be applied toSpringApplication
ornull
to use the default.protected List<ApplicationContextInitializer<?>>
getInitializers
(MergedContextConfiguration config, SpringApplication application) Return theinitializers
that will be applied to the context.protected String[]
protected String
protected String[]
protected SpringApplication
Builds newSpringApplication
instance.loadContext
(String... locations) void
processContextConfiguration
(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 newSpringApplication
instance. You can override this method to add custom behavior- Returns:
SpringApplication
instance
-
getEnvironment
Returns theConfigurableEnvironment
instance that should be applied toSpringApplication
ornull
to use the default. You can override this method if you need a custom environment.- Returns:
- a
ConfigurableEnvironment
instance
-
getInlinedProperties
-
getInitializers
protected List<ApplicationContextInitializer<?>> getInitializers(MergedContextConfiguration config, SpringApplication application) Return theinitializers
that will be applied to the context. By default this method will adaptcontext customizers
, addapplication initializers
and 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:
processContextConfiguration
in interfaceSmartContextLoader
- Overrides:
processContextConfiguration
in 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:
getResourceSuffixes
in classAbstractContextLoader
-
getResourceSuffix
- Specified by:
getResourceSuffix
in classAbstractContextLoader
-