Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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拦截器预处理如何获取实际请求。getServletPath()而不是';错误';如果发生错误_Spring_Spring Boot - Fatal编程技术网

Spring拦截器预处理如何获取实际请求。getServletPath()而不是';错误';如果发生错误

Spring拦截器预处理如何获取实际请求。getServletPath()而不是';错误';如果发生错误,spring,spring-boot,Spring,Spring Boot,如果rest api调用由错误的参数或错误的httpmethod进行,则在preHandle方法request中。getServletPath()返回“/error”,而不是实际请求的路径。。例如,如果使用POST调用资源GetMapping(“/test”),则request.getServletPath()返回/error,而不是/test。。我需要/测试信息 如何获得实际调用的资源路径 Spring启动版本=2.1.7 谢谢请分享代码。@dassum没有代码。。。如果使用Post调用资源G

如果rest api调用由错误的参数或错误的
httpmethod
进行,则在
preHandle
方法
request中。getServletPath()
返回
“/error”
,而不是实际请求的路径。。例如,如果使用
POST
调用资源
GetMapping(“/test”)
,则request.getServletPath()返回
/error
,而不是
/test
。。我需要/测试信息

如何获得实际调用的资源路径

Spring启动版本=2.1.7


谢谢

请分享代码。@dassum没有代码。。。如果使用Post调用资源GetMapping(“/test”),则request.getServletPath()返回/error而不是/test。。我需要/测试信息您使用的是spring boot还是old spring?@SounakSaha spring boot 2.1.7默认情况下,它会在出现错误时获取实际路径。您添加了任何自定义配置吗?你能分享整个项目吗?您可以使用默认配置查看my并运行它