【发布时间】:2012-01-17 21:24:55
【问题描述】:
我想在 init() 方法中对依赖 Spring 的 WebApplicationContextUtils.getRequiredWebApplicationContext(context) 的 servlet 代码进行单元测试。
下面是部分代码:
@Override
public void init() throws ServletException {
super.init();
WebApplicationContext applicationContext =
WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
this.injectedServiceBean = (SomeService) applicationContext.getBean("someBean");
}
将适当的 applicationContext.xml(测试版本)注入此文本的最佳方法是什么?
我知道 Spring 的 @ContextConfiguration,但我不确定将由该注释加载的 ${testClass}Test-context.xml 上下文注入 servlet 上下文的最佳方法,以便 getRequiredWebApplicationContext(... ) 可以退货。
【问题讨论】:
标签: java spring unit-testing servlets applicationcontext