Spring Boot-请求方法'POST'不支持
问题描述:
我的Spring Boot应用程序中出现异常PageNotFound: Request method 'POST' not supported
.
I got exception PageNotFound: Request method 'POST' not supported
in my Spring Boot app.
这是我的控制者:
@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
发送发帖请求,但不起作用.你有什么主意吗?
I am sending post request at localhost:8080/api/login
but it doesn't work. Have you got any idea?
UserDTO:
public class UserDTO implements Serializable {
private String email;
private String password;
//getters and setters
我发送的是json:
{
"email":"email@email.com",
"password":"password"
}
答
我通过禁用CSRF解决了这个问题.
I solved this issue by disabling the CSRF.
@Configuration
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}