我的Spring Boot应用程序中出现异常PageNotFound: Request method 'POST' not supported

这是我的 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);
    }
  }
}

我正在localhost:8080/api/login发送发帖请求,但不起作用。你有什么主意吗

编辑:

UserDTO:
public class UserDTO implements Serializable {

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

我发送的json:
{
   "email":"[email protected]",
   "password":"password"
}

最佳答案

我通过禁用CSRF解决了这个问题。

@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
    }
 }

10-06 01:21