当前位置: 代码迷 >> J2EE >> Struts2单元测试 Couldn't get resource paths for class path resource [WEB-INF/res/]解决方法
  详细解决方案

Struts2单元测试 Couldn't get resource paths for class path resource [WEB-INF/res/]解决方法

热度:226   发布时间:2016-04-22 01:59:50.0
Struts2单元测试 Couldn't get resource paths for class path resource [WEB-INF/res/]
我的项目是Struts2.2.1 + Spring3.0.5 + hibernate3的。
后来引入JUnit单元测试,在可行性实验中,遇到了以下这个问题。
我已经把struts2-junit-plugin-2.2.1.1.jar放入项,基本上都参数照了好几个博客,所以缺包或包冲突的可能性是很小了。
在我启动一个单元测试时,就抛出了下面的这个异常栈,这个异常虽然不影响我的测试结果,但每运行一个@Test的测试方法都抛出

一次,甚至一次抛出几个,有没有大虾帮我解决下这个问题,先谢了。

WARN: Couldn't get resource paths for class path resource [WEB-INF/res/]
java.io.FileNotFoundException: class path resource [WEB-INF/res/] 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:865)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration

(PackageBasedActionConfigBuilder.java:637)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs

(PackageBasedActionConfigBuilder.java:336)
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:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
at org.apache.struts2.util.StrutsTestCaseHelper.initDispatcher(StrutsTestCaseHelper.java:54)
at org.apache.struts2.StrutsTestCase.initDispatcher(StrutsTestCase.java:202)
at org.apache.struts2.StrutsTestCase.setUp(StrutsTestCase.java:188)
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:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
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)

------解决方案--------------------
WEB-INF/res/
这个目录不存在,无法通过url访问
------解决方案--------------------
你的测试类是继承StrutsSpringTestCase?

测试类中你是怎么加载String 配置文件的?
------解决方案--------------------
web-inf目录下的文件是不可以通过在地址栏里输入url直接访问的,必须使用servlet进行转发访问
如果是jsp页面,不建议楼主放在web-inf下,另外,能否看下测试用例?
  相关解决方案