405 Method not allowed in Spring Boot and Ajax

Hi I am having request mapping like this

@RequestMapping(value = "/pendodnp/{visitorId}/{content}")
public ResponseEntity<Object> setPendoDNP(@PathVariable String visitorId, @PathVariable String content, final HttpSession session, final HttpServletRequest request) throws PendoException {
    LOGGER.info("### pendodnp");
    _splitService.updateDNP(visitorId, content);
    return ResponseEntity.ok().body(content);
}

but when I hit this URL from an angular function, it gives "405 method not allowed" error.

    $http.get("pendodnp/"+visitorId+"/"+dnpValue, JSON.stringify(dnpValue))
        .success(function(response) {

Here is screenshot of how the request is going, can someone tell me what i am missing here?

enter image description here

Upvotes: 0

Views: 165

Answers (1)

E-Riz
E-Riz

Reputation: 32895

You haven't specified which HTTP method (GET, POST, PUT, DELETE, etc) the mapping should handle. To do that either use @GetMapping or change your @RequestMapping so it includes the method parameter.

@GetMapping("/pendodnp/{visitorId}/{content}")

Or

import static org.springframework.web.bind.annotation.RequestMethod.GET;
...
@RequestMapping(method = GET, path = "/pendodnp/{visitorId}/{content}")

Using @RequestMapping without a method parameter is usually only done at the class level, not individual methods. @GetMapping (or @PostMapping, @PutMapping, etc) are more common on controller methods.

Upvotes: 1

Related Questions