Spring不允许RequestMethod.DELETE

时间:2015-10-28 14:49:51

标签: spring-security spring-boot spring-restcontroller

我有这个端点调用我的服务方法,后​​者又调用我的repo类来删除用户,但是当我通过postman调用这个端点时,我得到一个请求方法不支持“打印在控制台中,任何帮助都会很大赞赏

@RequestMapping(value = "/{useId}/delete-user", method = RequestMethod.DELETE)
    public ResponseEntity<String> deleteUser(@PathVariable("userId") String userId){
        ResponseEntity<String> response = null;
        try {
            validate(userId);
            userService.deleteUser(Long.parseLong(userId));
            response = new ResponseEntity<String>(HttpStatus.NO_CONTENT);
        }catch (InputMismatchException e){
            response = new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
        } catch (UserNotFoundException e) {
            response = new ResponseEntity<String>(HttpStatus.NOT_FOUND);
        } catch (AccessDeniedException e) {
            response = new ResponseEntity<String>(HttpStatus.FORBIDDEN);
        }
        return  response;
    }

收到的邮件是Request method 'DELETE' not supported

1 个答案:

答案 0 :(得分:1)

@RequestMapping中有一个拼写错误。 userid拼写错误。这就是为什么Spring没有将DELETE映射到deleteUser方法