遇到一点小问题,doOut方法中的userService为null,而logout中的userService不会为null,怎么回事呢?doOut方法是服务器内部直接调用,logout是通过前端页面发送请求触发,是因为这个问题吗?这个问题怎么解决吗?
public void doOut(String sessionId) {
try {
System.err.println("----------准备退出------------------");
Subject subject = new Subject.Builder().sessionId(sessionId).buildSubject();
Sys_user user = (Sys_user) subject.getPrincipal();
subject.logout();
if (user != null) {
userService.update(Chain.make("isOnline", false), Cnd.where("id", "=", user.getId()));
sysOperateLogService.insertOperateLog(StringUtil.getRemoteAddr(), "退出", "成功退出系统", "用户退出系统", "系统操作日志", user.getId(), user.getUsername(), "3e967b028ba44a6c942b396e530df526");
}
System.err.println("----------执行了退出2------------------");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 退出系统
*/
@At("/logout")
@Ok(">>:/platform/login")
public void logout() {
try {
Subject currentUser = SecurityUtils.getSubject();
Sys_user user = (Sys_user) currentUser.getPrincipal();
currentUser.logout();
//退出后清空cookie
if (user != null) {
userService.update(Chain.make("isOnline", false), Cnd.where("id", "=", user.getId()));
sysOperateLogService.insertOperateLog(StringUtil.getRemoteAddr(), "退出", "成功退出系统", "用户退出系统", "系统操作日志", user.getId(), user.getUsername(), "3e967b028ba44a6c942b396e530df526");
}
} catch (SessionException ise) {
log.debug("Encountered session exception during logout. This can generally safely be ignored.", ise);
} catch (Exception e) {
log.debug("Logout error", e);
}
}
@Inject
private SysUserService userService;