namespace'/'在JUNIT中没有为范围'request'注册的Scope

时间:2014-03-05 02:46:52

标签: java spring unit-testing struts2 junit

我正在编写与Spring集成的Struts Action类的单元测试。

struts.xml中

<action name = "displaySearchCertiSchedulerAction" 
       class = "certificationSchedulerAction" 
      method = "displaySearchCertiScheduler">

    <result name = "success">/jsp/admin/SearchCertiScheduler.jsp</result>
</action>

的applicationContext.xml

<bean name = "certificationSchedulerAction"
     class = "com.admin.action.CertificationSchedulerAction"
     scope = "request">

    <property name = "certificationSchedulerServices" 
               ref = "certificationSchedulerServices" />
</bean>

JUnit的

@SuppressWarnings("rawtypes")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class BrokerActionTest extends StrutsSpringJUnit4TestCase {

    @Test
    public void testGetActionProxy() throws Exception {
        ActionProxy proxy   =  getActionProxy("/getEventCategoryAction");
        CertificationSchedulerAction schedulerAction = 
                                (CertificationSchedulerAction) proxy.getAction();

        assertNotNull(proxy);            
     }
}

错误:

  

错误测试:testGetActionProxy(com.admin.action.BrokerActionTest):   无法实例化定义的ActionSchedulerAction   名称空间'/'中的'getEventCategoryAction'   没有范围注册范围'请求'

如果我没有明确指定范围,这可以正常工作,但是如果我指定范围则会出错。

1 个答案:

答案 0 :(得分:1)

request范围(及其处理程序)由WebApplicationContext实现注册。如果您要在网络环境中进行测试,则需要@WebAppConfiguration