我想对WebApplicationContextUtils.getRequiredWebApplicationContext(context)
在其init()
方法中依赖于 Spring 的 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(...) 可以返回它。