0 0

StrutsSpringTestCase使用时的错误20

测试可以通过,但是会提示以下错误:
这个问题之前看到过,但没有找到解决方法,我的jsp页面不在content下, 如何能够避免查找content路径。

WARN [org.springframework.mock.web.MockServletContext] - <Couldn't get resource paths for class path resource [WEB-INF/content/system/]>
java.io.FileNotFoundException: class path resource [WEB-INF/content/system/] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:179)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:48)
at org.springframework.mock.web.MockServletContext.getResourcePaths(MockServletContext.java:205)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromResources(DefaultResultMapBuilder.java:254)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:191)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:864)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:636)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:335)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:436)
at org.apache.struts2.util.StrutsTestCaseHelper.initDispatcher(StrutsTestCaseHelper.java:54)
at org.apache.struts2.StrutsTestCase.initDispatcher(StrutsTestCase.java:196)
at org.apache.struts2.StrutsTestCase.setUp(StrutsTestCase.java:182)
at junit.framework.TestCase.runBare(TestCase.java:132)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
2012-07-27 13:33:04,843 WARN [org.springframework.mock.web.MockServletContext] - <Couldn't get resource paths for class path resource [WEB-INF/content/event/]>
java.io.FileNotFoundException: class path resource [WEB-INF/content/event/] cannot be resolved to URL because it does not exist

 

这是测试类,执行可以通过,结果也正确,只是继承类的setUP方法,每次都会先去找content路径,然后提示我找不到。接着再执行测试方法。

public class BackManStruts2Test extends StrutsSpringTestCase {
 
 
 @Override
 protected String[] getContextLocations() {
  return new String[]{"classpath*:appcontext-backman.xml"};
 }
 
 @Test
 public void testMethod(){
  ActionProxy proxyList = getActionProxy("/templateAction_list.action");
  TemplateAction actionList = (TemplateAction) proxyList.getAction();
  proxyList.execute();
  assertEquals("list", actionList.list());
  Long pkid = actionList.getTemplateList().get(0).getId();

 }
}

2012年7月27日 13:48

2个答案 按时间排序 按投票排序

0 0

采纳的答案

8) 刚才的回答是不正确的,父类在setUp中做了很多操作。

如果程序去寻找WEB-INF/content/
是因为你的lib下有struts2-convention-plugin-2.*.*.jar
你是想零配置吗?不需要,这个jar删除掉可能就不会寻找这个目录了。
另外这个目录是可以修改的:
<constant name="struts.convention.result.path" value="/WEB-INF/content" />

试试!~~

另外 Struts2官方就推荐使用Convention Plugin
约定大于配置 确实不错的选择。

2012年7月27日 14:29
0 0

@Override
setUp(){

}

给他覆盖掉!~

2012年7月27日 13:57

相关推荐

Global site tag (gtag.js) - Google Analytics