jeecgboot/JeecgBoot · error · JeecgBoot401Exception
用户不存在!
Error message
用户不存在!
What it means
Thrown by TokenUtils.verifyToken after the token is decoded and the username is extracted, but getLoginUser(username,...) returns null — the user does not exist in Redis (or, for the CommonAPI path, in the DB). Returns HTTP 401. It indicates the token refers to a user the backend can no longer find.
Source
Thrown at jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/TokenUtils.java:116
/**
* 验证Token
*/
public static boolean verifyToken(String token, CommonAPI commonApi, RedisUtil redisUtil) {
if (StringUtils.isBlank(token)) {
throw new JeecgBoot401Exception("token不能为空!");
}
// 解密获得username,用于和数据库进行对比
String username = JwtUtil.getUsername(token);
if (username == null) {
throw new JeecgBoot401Exception("token非法无效!");
}
// 查询用户信息
LoginUser user = TokenUtils.getLoginUser(username, commonApi, redisUtil);
//LoginUser user = commonApi.getUserByName(username);
if (user == null) {
throw new JeecgBoot401Exception("用户不存在!");
}
// 判断用户状态
if (user.getStatus() != 1) {
throw new JeecgBoot401Exception("账号已被锁定,请联系管理员!");
}
// 校验token是否超时失效 & 或者账号密码是否错误
if (!jwtTokenRefresh(token, username, user.getPassword(), redisUtil)) {
// 用户登录Token过期提示信息
String userLoginTokenErrorMsg = oConvertUtils.getString(redisUtil.get(CommonConstant.PREFIX_USER_TOKEN_ERROR_MSG + token));
throw new JeecgBoot401Exception(oConvertUtils.isEmpty(userLoginTokenErrorMsg)? CommonConstant.TOKEN_IS_INVALID_MSG: userLoginTokenErrorMsg);
}
return true;
}
/**
* 刷新token(保证用户在线操作不掉线)
* @param token
* @param userNameView on GitHub (pinned to 96fb33f5ec)
Solutions
- Treat this as a hard session end: clear the client token and require re-login.
- Verify the Redis connection and database index are consistent across all app nodes (spring.redis.database, host, port).
- Confirm the user still exists and has status=1 in sys_user_table.
- If the cache was intentionally cleared, broadcast a logout/refresh so clients re-authenticate.
Example fix
// before: stale token after user deletion
// user clicks around -> 401 '用户不存在!'
// after (frontend)
if (err.response.status === 401) {
Vue.ls.clear();
router.push('/user/login');
} Defensive patterns
Strategy: fallback
Validate before calling
LoginUser u = TokenUtils.getLoginUser(username, commonApi, redisUtil);
if (u == null) { /* clear client token, redirect to login */ } Type guard
public static boolean userResolvable(String username){
return username != null && TokenUtils.getLoginUser(username, commonApi, redisUtil) != null;
} Try / catch
try { TokenUtils.verifyToken(token, ...); }
catch (JeecgBoot401Exception e) { clearSession(); redirect("/login"); } Prevention
- Keep Redis persistent or replicate sessions during deploys.
- Use the same Redis DB index across nodes.
- Handle user-deletion by revoking tokens.
When it happens
Trigger: The user was deleted or never existed; the Redis user cache was flushed/expired while the JWT itself is still structurally valid; a multi-node deploy where the user logged in on a node whose Redis is a different instance; or the username claim in the token was tampered to refer to a non-existent account.
Common situations: Admin deleted a user account mid-session; Redis was restarted/cleared; wrong Redis DB index configured (spring.redis.database) so the user cache is in another db; deployment switched from standalone to cluster Redis without migrating sessions.
Related errors
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/e96e49b74f254698.
Report an issue: GitHub.