Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - Request method 'POST' not supported

I got exception PageNotFound: Request method 'POST' not supported in my Spring Boot app.

This is my controller:

@RestController
public class LoginController {

UserWrapper userWrapper = new UserWrapper();

@RequestMapping(value = "/api/login", method = RequestMethod.POST, headers = "Content-type: application/*")
public @ResponseBody ResponseEntity getCredentials(@RequestBody UserDTO userDTO) {

    User user = userWrapper.wrapUser(userDTO);
    if (userDTO.getPassword().equals(user.getPassword())) {
        return new ResponseEntity(HttpStatus.OK);
    } else {
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }
  }
}

I am sending post request at localhost:8080/api/login but it doesn't work. Have you got any idea?

EDIT:

UserDTO:

public class UserDTO implements Serializable {

private String email;
private String password;
//getters and setters

And json i send:

{
   "email":"[email protected]",
   "password":"password"
}
like image 754
Bartek Avatar asked Feb 25 '15 10:02

Bartek


People also ask

Which of the given HTTP mapping methods spring rest doesn't support?

Spring declares all the supported request methods under an enum, RequestMethod, which specifies the standard GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, and TRACE verbs. The Spring DispatcherServlet supports all of them by default, except OPTIONS and TRACE.

Does not support GET request method?

The spring boot exception Request method 'GET' not supported exists when the request method is not configured as 'GET' in one of the rest controller methods and is requested using the HTTP GET method. The request method is configured in annotation @RequestMapping.


1 Answers

I solved this issue by disabling the CSRF.

@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
    }
 }
like image 172
Balaji Avatar answered Sep 28 '22 20:09

Balaji