【问题标题】:Client can't target spring method客户端无法定位spring方法
【发布时间】:2013-06-19 11:12:07
【问题描述】:

我的客户未能“定位”一个方法,我在服务器日志中没有得到反馈。这对我来说很奇怪。

我的方法定义如下:

    @RequestMapping(value = "/reUploadFile/{userId}/{fileId}", method = RequestMethod.POST, headers = "Accept=*")
    public @ResponseBody()
    void reUploadFile(@PathVariable("userId") int userId, @PathVariable("fileId") int fileId,
            @RequestParam(value = "file") MultipartFile multipartFile,
            Model model, HttpServletRequest request, HttpServletResponse response) {

    ...Stuff happends doesn't get called
    }

它几乎与以下有效的方法相同:

@RequestMapping(value = "/uploadFile/{companiesId}/{day}/{month}/{year}/{userId}",
    method = RequestMethod.POST, headers = "Accept=*")
    public void uploadFile(@PathVariable("companiesId") long companiesId,
            @PathVariable("day") int day, @PathVariable("month") int month,
            @PathVariable("year") int year, @PathVariable("userId") int userId,
            @RequestParam(value = "file") MultipartFile multipartFile,
            Model model, HttpServletRequest request, HttpServletResponse response) {
     ...content
    }

我在 chrome 中的网络管理器如下所示: 失败者:

Request URL:http://localhost:8080/MyProject.spring/spring/reUploadFile/3821211/154329
Request Method:POST
Status Code:500 Internal Server Error

成功:

Request URL:http://localhost:8080/MyProject.spring/spring/uploadFile/25974093/01/06/2013/3821211
Request Method:POST
Status Code:200 OK

谁能弄清楚为什么我在这里收到错误 500? 如果您需要更多信息,请您好,我会告诉您的 :) 感谢阅读:)

【问题讨论】:

  • 尝试从reUploadFile 中删除@ResponseBody(),这似乎是唯一的区别。如果您想保留它,请在服务器上发布异常。
  • 能不能发个错误日志
  • @SanjayaLiyanage 我在服务器日志中没有得到反馈。所以这种方式也意味着没有错误日志。否则谢谢:)
  • @BalintBako ResponseBody 不会导致错误,尽管您将其设置为 void
  • 您确定您没有在 uploadFile 方法中处理错误吗?

标签: java spring annotations


【解决方案1】:

状态码:500 内部服务器错误表示您的 reUploadFile 方法中的逻辑有问题。它可以毫无问题地找到端点(url),检查您的逻辑中是否引发了任何异常。我猜 multipartFile 没有正确设置。

【讨论】:

  • 不,显然没有,我已经调试过,并试图在第一行停止。而且它永远不会到那个地步
  • 那么问题必须在这里 "@RequestParam(value = "file") MultipartFile multipartFile" 。只需将此参数设置为 false 或临时删除此部分并测试。
【解决方案2】:

您无需提供@ResponseBody(),因为您的响应类型是无效的。所以删除并重试

【讨论】:

  • @ResponseBody 不会导致错误,尽管您将其设置为 void.Hense -1 from me
猜你喜欢
  • 1970-01-01
  • 2020-10-08
  • 1970-01-01
  • 2019-12-26
  • 2015-06-02
  • 1970-01-01
  • 2022-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多