ContextConfiguration RunWith WebAppConfiguration注释

我有一个注释这些注释的类:

@ContextConfiguration(locations = { "classpath:pathToXml.xml" }) @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration 

你能解释一下我在课堂上添加这些注释后的function吗?

您将获得@WebAppConfiguration配置javadoc中描述的function。

WebApplicationContext主要更改资源的加载方式,即具有未指定资源前缀的资源将从src/main/webappvalue参数中的位置加载(否则它们在Spring上下文中不可用,因为通常不包含webapp文件夹到classpath)而不是classpath: .

此外,您还可以测试使用其他WebApplicationContextfunction的代码 – ServletContextAware bean,Session和Request bean范围等。

这意味着您将能够使用Spring MVC Test Framework