无法获取类路径资源的资源路径 [英] Couldn't get resource paths for class path resource

查看:49
本文介绍了无法获取类路径资源的资源路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,我对struts2动作单元测试感到困惑

all, I am puzzled about the struts2 action unit test

import org.apache.struts2.StrutsSpringTestCase;
import org.junit.Test;
import com.opensymphony.xwork2.ActionProxy;

public class TestLoginAction extends StrutsSpringTestCase {
    @Test
    public void testCheck() throws Exception {
        ActionProxy proxy = null;
        LoginAction test = null;

        request.setParameter("username", "admin");
        proxy = getActionProxy("/checkLogin");
        test = (LoginAction) proxy.getAction();

        String result = proxy.execute();

        assertEquals("error", result);
        assertEquals("admin", test.getUsername());

    }
}

它抛出警告和异常:

无法获取类路径资源的资源路径 [WEB-INF/jsp/]java.io.FileNotFoundException: 类路径资源 [WEB-INF/jsp/] 无法解析为 URL,因为它不存在

Couldn't get resource paths for class path resource [WEB-INF/jsp/] java.io.FileNotFoundException: class path resource [WEB-INF/jsp/] cannot be resolved to URL because it does not exist

推荐答案

StrutsSpringTestCase 期望从 classpath:applicationContext.xml 加载 Spring 配置.您可以通过将其添加到您的测试操作来覆盖此行为:

StrutsSpringTestCase is expecting the Spring configuration to be loaded from classpath:applicationContext.xml. You can override this behavior by adding this to your test action:

@Override
public String getContextLocations() {
    return "path/to/your/TestLoginAction-context.xml";
}

这篇关于无法获取类路径资源的资源路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆