这一行:
Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token).getBody();
Run Code Online (Sandbox Code Playgroud)
当我的 jwt 令牌过期时抛出这样的错误:
JWT 于 2020-05-13T07:50:39Z 过期。当前时间:2020-05-16T21:29:41Z。
更具体地说,正是这个函数抛出了“ExpiredJwtException”异常:

我该如何处理这些异常?我是否应该捕获它们并将错误消息发送回客户端并强制它们重新登录?
如何实现刷新令牌功能?我在后端使用 Spring 和 mysql,在前端使用 vuejs。
我生成这样的初始令牌:
@Override
public JSONObject login(AuthenticationRequest authreq) {
JSONObject json = new JSONObject();
try {
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(authreq.getUsername(), authreq.getPassword()));
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
List<String> roles = userDetails.getAuthorities().stream().map(item -> item.getAuthority())
.collect(Collectors.toList());
if (userDetails != null) {
final String jwt = jwtTokenUtil.generateToken(userDetails);
JwtResponse jwtres = new JwtResponse(jwt, userDetails.getId(), userDetails.getUsername(),
userDetails.getEmail(), roles, jwtTokenUtil.extractExpiration(jwt).toString());
return json.put("jwtresponse", jwtres);
}
} catch (BadCredentialsException ex) {
json.put("status", "badcredentials"); …Run Code Online (Sandbox Code Playgroud)