Announcement Announcement Module
No announcement yet.
How to redirect properly in RESTful Spring MVC controller? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to redirect properly in RESTful Spring MVC controller?

    I'm trying to implement a simple REST WS. When I'm trying to send PUT request to the handler of my controller all works fine

        @RequestMapping(method = PUT,
                        consumes = "application/json",
                        headers = "content-type=application/json")
        public String updateCompany(@RequestBody Company company) {
            return "redirect:/api/company/" + company.getId();
        @RequestMapping(value = "/{id}", method = GET,
                        produces = "application/json")
        public @ResponseBody Company getCompany(@PathVariable("id") Integer id) {
            Company c = companyRepository.getCompany(id);
            return new CompanyToJsonWrapper(c);
    I'm getting HTTP Status 405 - Request method 'PUT' not supported error. Any ideas how to fix it?

  • #2
    Could you provide us the HTTP requests and responses?
    What kind of HTTP client are you using?
    It looks like your HTTP client is sending a PUT request to the redirect location, when a GET is clearly necessary.

    This question is probably a better candidate for StackOverflow, perhaps with the "spring" and "spring-mvc" tags.

    Could you post your question there?
    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: