Sasanka Panguluri Sasanka Panguluri - 2 years ago 693
Java Question

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 {



The controller is mapped using

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

Authorization: "test:<stuff>"

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

Answer Source

This will work:

@RequestMapping(value = "/{authorizationUrl}", method = DELETE)
public @ResponseBody 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download