org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示

时间:2015-03-05 17:59:57

标签: java spring-mvc

我有一个用户可以下载存档的服务

@RequestMapping(value = "/{resource}/zip", method = RequestMethod.GET, produces="application/zip")
    public void downloadArchive(@PathVariable("resource") String resource, HttpServletResponse response) {
        SomeResource some= someResourceService.get(resource); //If no resource found custom NoDataException.class is thrown
        //archive and write out to response object 
}

应生成zip。

我也有异常处理程序方法

@ExceptionHandler(NoDataException.class)
@ResponseBody
public ResponseEntity<ExceptionMessage> handleNoResultException(Exception e) {
    logger.error(e.getMessage(), e);
    return new ResponseEntity<>(new ExceptionMessage(e.getMessage()), HttpStatus.NOT_FOUND);
}

生成application / json

如果找不到资源,我希望收到404。但是我得到500

  

org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示

0 个答案:

没有答案