Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring MockHttpServletRequest的realPath_Spring_Realpath - Fatal编程技术网

Spring MockHttpServletRequest的realPath

Spring MockHttpServletRequest的realPath,spring,realpath,Spring,Realpath,我正在为我的Spring控制器编写一个基于Spring的测试用例,在我的控制器中,我们使用如下“request.getSession().getServletContext().getRealPath(“/myFolderName”);” 对于普通请求,它可以正常工作,但是对于MockHttpServletRequest这样的单元测试用例,上面的方法调用给出的是null。如何获取MockHttpServletRequest的realPath 谢谢, Praneth.默认情况下,MockHttpS

我正在为我的Spring控制器编写一个基于Spring的测试用例,在我的控制器中,我们使用如下“request.getSession().getServletContext().getRealPath(“/myFolderName”);” 对于普通请求,它可以正常工作,但是对于MockHttpServletRequest这样的单元测试用例,上面的方法调用给出的是null。如何获取MockHttpServletRequest的realPath

谢谢,
Praneth.

默认情况下,
MockHttpServletRequest
的作用就像根webapp文件夹是一个类路径一样,因此您应该能够对类路径资源使用
getRealPath()


或者,您可以为
MockHttpServletRequest
提供
MockServletContext
,并且
MockServletContext
可以为
getRealPath()
等配置特定的根文件夹。

将语句拆分为几个较小的语句,以便您可以看到哪个部分导致了NPE。或者使用调试器。