Search code examples
spring-securityspring-bootspring-restcontroller

Spring not allowing RequestMethod.DELETE


I have this endpoint that invoke my service method which in turn call my repo class to Delete a user, but when i call this endpoint through postman i get a request Method not supported" printed in the console,any help would be greatly appreciated

@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;
    }

The message received is Request method 'DELETE' not supported


Solution

  • There is a typo in the @RequestMapping. userid is misspelled. That is why Spring is not mapping the DELETE to deleteUser method