类 SpringBootContextLoader
- java.lang.Object
- org.springframework.test.context.support.AbstractContextLoader
- org.springframework.boot.test.context.SpringBootContextLoader
- 所有已实现的接口:
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 web server.If
@ActiveProfilesare provided in the test class they will be used to create the application context.- 另请参阅:
SpringBootTest
构造器概要
构造器 构造器 说明 SpringBootContextLoader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected Class<?>[]detectDefaultConfigurationClasses(Class<?> declaringClass)Detect the default configuration classes for the supplied test class.protected org.springframework.core.env.ConfigurableEnvironmentgetEnvironment()Builds a newConfigurableEnvironmentinstance.protected List<org.springframework.context.ApplicationContextInitializer<?>>getInitializers(org.springframework.test.context.MergedContextConfiguration config, org.springframework.boot.SpringApplication application)Return theinitializersthat will be applied to the context.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)
构造器详细资料
SpringBootContextLoader
public SpringBootContextLoader()
方法详细资料
loadContext
public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration config) throws Exception
- 抛出:
Exception
getSpringApplication
protected org.springframework.boot.SpringApplication getSpringApplication()
Builds newSpringApplicationinstance. You can override this method to add custom behavior- 返回:
SpringApplicationinstance
getEnvironment
protected org.springframework.core.env.ConfigurableEnvironment getEnvironment()
Builds a newConfigurableEnvironmentinstance. You can override this method to return something other thanStandardEnvironmentif necessary.- 返回:
- a
ConfigurableEnvironmentinstance
getInlinedProperties
protected String[] getInlinedProperties(org.springframework.test.context.MergedContextConfiguration config)
getInitializers
protected List<org.springframework.context.ApplicationContextInitializer<?>> getInitializers(org.springframework.test.context.MergedContextConfiguration config, org.springframework.boot.SpringApplication application)
Return theinitializersthat will be applied to the context. By default this method will adaptcontext customizers, addapplication initializersand addinitializers specified on the test.- 参数:
config- the source context configurationapplication- the application instance- 返回:
- the initializers to apply
- 从以下版本开始:
- 2.0.0
processContextConfiguration
public void processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
- 指定者:
processContextConfiguration在接口中org.springframework.test.context.SmartContextLoader- 覆盖:
processContextConfiguration在类中org.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<?>).- 参数:
declaringClass- the test class that declared@ContextConfiguration- 返回:
- an array of default configuration classes, potentially empty but never
null - 另请参阅:
AnnotationConfigContextLoaderUtils
loadContext
public org.springframework.context.ApplicationContext loadContext(String... locations) throws Exception
- 抛出:
Exception
getResourceSuffixes
protected String[] getResourceSuffixes()
- 覆盖:
getResourceSuffixes在类中org.springframework.test.context.support.AbstractContextLoader
getResourceSuffix
protected String getResourceSuffix()
- 指定者:
getResourceSuffix在类中org.springframework.test.context.support.AbstractContextLoader