Search code examples
javaspringspring-mvchttp-status-code-405http-delete

Spring - 405 Http method DELETE is not supported by this URL


Well I have a strange problem with executing a "DELETE" HTTP request in Spring.

I have a controller method which I have mapped a DELETE request to:

    @RequestMapping(value = "/{authorizationUrl}",method=DELETE)
    public void deleteAuthorizationServer(
            @RequestHeader(value="Authorization") String authorization,
            @PathVariable("authorizationUrl") String authorizationUrl)
            throws  IOException {

        System.out.println("TEST");

    }

The controller is mapped using @RequestMapping("/authorization_servers"); When I send a request through my DEV Http Client, I am getting the response : 405 Http method DELETE is not supported by this URL.

The request looks like this:

 DELETE    localhost:8080/authorization_servers/asxas

  Headers:
  Authorization: "test:<stuff>"

If someone can look into this and help me, I would be grateful


Solution

  • This will work:

    @RequestMapping(value = "/{authorizationUrl}", method = DELETE)
    @ResponseBody
    public void deleteAuthorizationServer(
        @RequestHeader(value="Authorization") String authorization,
        @PathVariable("authorizationUrl") String authorizationUrl
    ){
        System.out.printf("Testing: You tried to delete %s using %s\n", authorizationUrl, authorization);
    }
    

    You were missing @ResponseBody. Your method was actually getting called; it was what happened after that that was producing the error code.