我试图捕捉错误情况,但我在所有情况下都会遇到异常。
以下是我的代码段:
@RequestMapping(value = "/config/file/data", method = RequestMethod.GET)
@ResponseBody
@ExceptionHandler(RestClientException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Not Found")
public void restClientException()
{
//do nothing
}
public List<myfile> getAllmyfiles() throws RestClientException
{
return myfileService.getAllmyfiles();
}
答案 0 :(得分:0)
试试这个:
@ExceptionHandler(RestClientException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Not Found")
public void restClientException()
{
//do nothing
}
@RequestMapping(value = "/config/file/data", method = RequestMethod.GET)
@ResponseBody
public List<myfile> getAllmyfiles() throws RestClientException
{
return myfileService.getAllmyfiles();
}
您不应将@RequestMapping
与@ExceptionHandler
一起使用:当引发指定的异常时,会自动调用使用@ExceptionHandler
注释的方法