Reputation: 57
I load at browser as localhost:8080/picking/addPick get error HTTP Status 405 - Request method 'GET' not supported.
What wrong?Hope advice thanks
@Controller
@RequestMapping("/picking")
public class PickerController {
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody ArrayList getAllPickingItems()throws SQLException, ClassNotFoundException{
//....
}
@RequestMapping(value="/addPick",method=RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public Boolean add(@RequestBody PickingInfo pickingInfo,HttpServletResponse response){
try{
Boolean success = pickerMethod.addPickingInfo(pickingInfo);
response.setHeader("addPickingInfo", success+"");
return true;
}catch(Exception ex){
System.out.println(ex.getMessage());
}
return false;
}
}
Upvotes: 1
Views: 5798
Reputation: 3527
You limited URI/picking/addPick
to POST requests :
@RequestMapping(value="/addPick",method=RequestMethod.POST)
When you try to open that URI from your browser you're sending a GET request, not a POST. If you want to be able to access /picking/addPick from your browser you must either :
method=RequestMethod.POST
method = { RequestMethod.POST, RequestMethod.GET }
If you just want to test a POST method, use SoapUI. Simply create a "New REST Project", paste your service URI, and send any type of HTTP Request you want.
Upvotes: 2
Reputation: 64011
You have mapped /addPick to the add
method only for POST requests. Therefor GET is not mapped to anything (and in this case there is no point in mapping get to the method since you are also using @RequestBody
)
Upvotes: 0