Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 boot 未捕获异常:类org.springframework.web.HttpRequestMethodNotSupportedException:Request方法';把';不支持_Spring Boot - Fatal编程技术网

Spring boot 未捕获异常:类org.springframework.web.HttpRequestMethodNotSupportedException:Request方法';把';不支持

Spring boot 未捕获异常:类org.springframework.web.HttpRequestMethodNotSupportedException:Request方法';把';不支持,spring-boot,Spring Boot,我在Spring boot中创建了PatchMapping 当我想修改和我使用的方法把它 ====错误:未捕获异常:类org.springframework.web.HttpRequestMethodNotSupportedException: 不支持请求方法“PUT”================== 如果我使用方法补丁它工作正常。如果您想通过执行PUT动词来调用服务,则需要添加spring引导注释: @RequestMapping(path = "/yourURL", method

我在Spring boot中创建了
PatchMapping
当我想修改和我使用的方法把它

====错误:未捕获异常:类org.springframework.web.HttpRequestMethodNotSupportedException: 不支持请求方法“PUT”==================


如果我使用方法
补丁
它工作正常。

如果您想通过执行PUT动词来调用服务,则需要添加spring引导注释:

    @RequestMapping(path = "/yourURL", method = RequestMethod.PUT)
补丁和PUT不一样。您可以在以下网站上找到更多信息:


如果要捕获异常,请创建一个实现ErrorController的类:

@Controller
@ControllerAdvice
public class RestErrorHandler implements ErrorController {

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    public ResponseEntity<RestInvalidParameter> processValidationError(MethodArgumentNotValidException ex) {
        return new ResponseEntity<>(ex, HttpStatus.BAD_REQUEST);
    }
}
@控制器
@控制器建议
公共类RestErrorHandler实现ErrorController{
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
公共响应验证过程错误(MethodArgumentNotValidException ex){
返回新的响应属性(例如,HttpStatus.BAD_请求);
}
}

显示您在restcontroller中使用的实际代码我有Patchmapping,而没有putMapping,因此当我使用put from client side it error 500“内部服务器错误”时。所以我想返回到用户错误400“put method not have”。我相信我们理解您有问题,但我们只能在看到您的代码时修复您的代码,否则这只是一个疯狂的猜测游戏。异常告诉我们,
请求方法“put”不受支持
。与
POST
PATCH
无关。确定。如果需要进行更新,则需要将服务声明为method=RequestMethod.PUT,而不是POST。在包含要更新的值的输入参数上也需要注释@RequestBody。谢谢,但当我使用正常工作的修补程序时,但我想在使用方法put时处理,现在错误{“status”:500,“message”:“internal server error”}我想处理它并返回400。如何在Spring中捕获restcontroller中的异常方法您需要一个实现ErrorController的类@ExceptionHandler(MethodArgumentNotValidException.class)public ResponseEntity processValidationError(MethodArgumentNotValidException ex){RestInvalidParameter error=new RestInvalidParameter(ex);LOGGER.log(Level.WARNING,“error:{0}”,error);返回新的ResponseEntity(error,HttpStatus.BAD_请求);}@Nacho对于类
RestErrorHandler
@ExceptionHandler(Exception.class)public void methodNotAllowed(Exception ex)不需要实现
ErrorController
,抛出ResourceNotFoundException、URISyntaxException、ResourceViolationException、ResourceNotFoundException、ResourceNotFoundException{throw ex;}请解决ResourceNotFoundException、URISyntaxException、ResourceViolationException、ResourceNotFoundException、ResourceNotFoundException,它们是从exception扩展而来的类,但我不知道在使用exception时哪个类有错误。@Nacho有什么想法吗?您可以将集合设置为annotation@ExceptionHandler({ResourceNotFoundException.class、URISyntaxException.class、ResourceViolationException.class},例如,在方法内部,使用“instanceof”为每个异常抛出不同的HttpStatus。