gpt4 book ai didi

java - 无法获取类路径资源的资源路径

转载 作者:行者123 更新时间:2023-12-04 06:11:20 25 4
gpt4 key购买 nike

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

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());

}
}

它抛出警告和异常:

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 配置。您可以通过将其添加到您的测试操作来覆盖此行为:

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

关于java - 无法获取类路径资源的资源路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7734695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com