Rohit Yadbole
Rohit Yadbole

Reputation: 65

Spring MVC ResquestMapping 'POST' not supported

enter image description hereI have a method with get and post in login controller. When application is deployed from index page i am redirecting to login page it makes GET request(/login.htm) it works fine but when i make post request with JSON body it says Request method 'POST' not supported i am using postman tool to test please

Help

@RequestMapping(value="/login",method = RequestMethod.GET)
public ModelAndView redirectLoginForm()
{
    System.out.println("Login Page...");
    return new ModelAndView("login");
}

@RequestMapping(value="/login",method=RequestMethod.POST,
                                consumes=MediaType.APPLICATION_JSON_VALUE,
                                produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Login> login(@RequestBody Login login)
{
            System.out.println("Checking LoginCredentials...");

            boolean isValid=loginServiceBo.checkUserLogin(login);

            if(isValid)
            {
                return new ResponseEntity<Login>(login, HttpStatus.ACCEPTED);
            }

            return new ResponseEntity<>(login, HttpStatus.NOT_FOUND);   
}

Upvotes: 0

Views: 79

Answers (2)

voliveira89
voliveira89

Reputation: 1294

Taking in account your code:

@RequestMapping(value="/login",method=RequestMethod.POST,
                            consumes=MediaType.APPLICATION_JSON_VALUE,
                            produces=MediaType.APPLICATION_JSON_VALUE)

In the screenshot of Postman, is missing the correct mapping, it should be: http://localhost:8073/Spring_Hibernate_Project/login

Upvotes: 1

Alarmwolf
Alarmwolf

Reputation: 158

I think it's connected with your postman query.

May be my screenshot will be helpful to check your postman, on server side I have very similar mapping.

enter image description here

Upvotes: 0

Related Questions