|
对于最新的稳定版本,请使用 Spring Framework 6.2.10! |
@WebAppConfiguration
@WebAppConfiguration是一个类级注解,可用于声明ApplicationContextloaded for an integration test 应该是WebApplicationContext.
仅仅是@WebAppConfiguration在测试类上确保WebApplicationContext加载以进行测试,使用默认值"file:src/main/webapp"对于 Web 应用程序根目录的路径(即
资源基础路径)。资源基础路径在后台用于创建MockServletContext,它充当ServletContext对于测试的WebApplicationContext.
以下示例演示如何使用@WebAppConfiguration注解:
-
Java
-
Kotlin
@ContextConfiguration
@WebAppConfiguration (1)
class WebAppTests {
// class body...
}
| 1 | 这@WebAppConfiguration注解。 |
@ContextConfiguration
@WebAppConfiguration (1)
class WebAppTests {
// class body...
}
| 1 | 这@WebAppConfiguration注解。 |
要覆盖默认值,您可以使用
含蓄value属性。双classpath:和file:资源前缀是
支持。如果未提供资源前缀,则假定路径为文件系统
资源。以下示例显示了如何指定类路径资源:
-
Java
-
Kotlin
@ContextConfiguration
@WebAppConfiguration("classpath:test-web-resources") (1)
class WebAppTests {
// class body...
}
| 1 | 指定类路径资源。 |
@ContextConfiguration
@WebAppConfiguration("classpath:test-web-resources") (1)
class WebAppTests {
// class body...
}
| 1 | 指定类路径资源。 |
请注意@WebAppConfiguration必须与@ContextConfiguration,无论是在单个测试类中还是在测试类中
等级制度。请参阅@WebAppConfigurationjavadoc 了解更多详情。