Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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
Java RestClientException:在spring控制器中_Java_Spring - Fatal编程技术网

Java RestClientException:在spring控制器中

Java RestClientException:在spring控制器中,java,spring,Java,Spring,我试图捕捉控制器中的错误场景,但在所有情况下都会出现异常 下面是我的代码片段: @ResponseBody @ExceptionHandler(RestClientException.class) @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Not Found") public void restClientException() { //do nothing } public List<myfile> 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();
}
@ResponseBody
@ExceptionHandler(RestClientException.class)
@ResponseStatus(value=HttpStatus.NOT_FOUND,reason=“NOT FOUND”)
public void restClientException()
{
//无所事事
}
public List getAllmyfiles()引发RestClientException
{
返回myfileService.getAllmyfiles();
}

我想你在这里搞混了。 当服务器无法访问时,您的控制器将不可用,无法工作


如果您想在服务器不可用时执行某些逻辑,则必须在前端(例如,JS)中执行。不能在控制器对象中执行此操作

我在代码中做错了什么?我刚到春天。如果无法访问服务器,我将尝试捕获异常