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

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.


Your annotation should look like this:

@RequestMapping(value = "/{authorizationUrl}",method=RequestMethod.DELETE)

I don't know where you got that DELETE variable from. :-)


If the @RequestMapping pattern doesn't match or is invalid, it results in a 404 not found. However, if it happens to match another mapping with a different method (ex. GET), it results in this 405 Http method DELETE is not supported.

My issue was just like this one, except my requestMapping was the cause. It was this:

@RequestMapping(value = { "/thing/{id:\\d+" }, method = { RequestMethod.DELETE })

Do you see it? The inner closing brace is missing, it should be: { "/thing/{id:\\d+}" } The \\d+ is a regular expression to match 1 or more numeric digits. The braces delimit the parameter in the path for use with @PathVariable.

Since it's invalid it can't match my DELETE request: http://example.com/thing/33 which would have resulted in a 404 not found error, however, I had another mapping for GET:

@RequestMapping(value = { "/thing/{id:\\d+}" }, method = { RequestMethod.GET })

Since the brace pattern is correct, but it's not a method DELETE, then it gave a error 405 method not supported.