Home Ask Login Register

Developers Planet

Your answer is one click away!

Kavv February 2016

Request method 'GET' not supported but it's actually present in Controller

I was developing a simple CRUD application, when i've encountered a this weird error. Weird, because in my controller class convenient @RequestMapping annotated method is present with request GET method mapping. The requested URI is [context]/purchase/change/2. The error is following:

org.springframework.web.servlet.PageNotFound - Request method 'GET' not supported

and there is my controller:

public class PurchasesController {


    @RequestMapping(value = "/add/{userId}", method = RequestMethod.GET)
    public String addPurchase(Model model, @PathVariable int userId) {
        //that method works with mapping ex. "context/purchase/add/1"
        return "purchase_update_add";

    @RequestMapping(value = "/add/{userId}", method = RequestMethod.POST)
    public String addPurchase(
            @ModelAttribute("purchase") PurchaseDTO purchaseDto,
            @PathVariable int userId) {

        //that works too

        return "redirect:/user/" + userId;

    @RequestMapping(value = "/change/${purchaseId}", method = RequestMethod.GET)
    public String changePurchaseDate(Model model, @PathVariable int purchaseId) {

        model.addAttribute("operation", "change");

        PurchaseDTO purchase = new PurchaseDTO();
        Purchase purchaseEntity = purchasesDAO.getPurchase(purchaseId);

        model.addAttribute("purchase", purchase);

        return "purchase_update_add";

    @RequestMapping(value = "/change/{userId}", method = RequestMethod.POST)
    public String changePurchaseDate(
            @ModelAttribute("purchase") PurchaseDTO purchaseDto,
            @PathVariable int userId) {
        Purchase purchase = purchasesDAO.getPurchase(purchaseDto.getId());


Ali Dehghani February 2016

You've created a Path Variable with ${...} syntax:

@RequestMapping(value = "/change/${purchaseId}", method = RequestMethod.GET)
                                 ^ $ is redundant

Use the correct {...} syntax instead:

@RequestMapping(value = "/change/{purchaseId}", method = RequestMethod.GET)

Post Status

Asked in February 2016
Viewed 3,450 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life