我越来越threw exception
java.lang.IllegalStateException: getWriter() has already been called for this response
at org.apache.catalina.connector.Response.getOutputStream(Response.java:544)
同时从 angular2 传达我的服务器端代码(RESTFul,Spring-boot(。两者都部署在同一台服务器上 (Tomcat 8.0.2(。
以下是我的代码
@RequestMapping(value="/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public User login() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User user = (User) principal;
return user;
}
如何解决这个问题?
更改 :
@RequestMapping(value="/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public User login(Principal principal) {
User user = (User) principal; // take care of the conversion!
return user;
}
或
@RequestMapping(value="/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public User login(Authentication authentication) {
User user = (User) authentication.getPrincipal(); // take care of the conversion!
return user;
}