PUT and POST getting 405 Method Not Allowed Error for Restful Web Services

后端 未结 6 2333
无人及你
无人及你 2020-12-09 18:32

I am trying to set up a simple Restful Web-Service which returns either JSON or XML according to the Accept header. I am using Spring, Maven and WebLogic Server. I took the

6条回答
  •  旧时难觅i
    2020-12-09 19:13

    Well, apparently I had to change my PUT calling function updateUser. I removed the @Consumes, the @RequestMapping and also added a @ResponseBody to the function. So my method looked like this:

    @RequestMapping(value="/{id}",method = RequestMethod.PUT)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public void updateUser(@PathVariable int id, @RequestBody User temp){
        Set set1= obj2.getUsers();
        for(User a:set1)
        {
            if(id==a.getId())
            {
                set1.remove(a);
                a.setId(temp.getId());
                a.setName(temp.getName());
                set1.add(a);
            }
        }
        Userlist obj3=new Userlist(set1);
        obj2=obj3;
    }
    

    And it worked!!! Thank you all for the response.

提交回复
热议问题