我需要在mi中使用JWT,IDE告诉我.signWith()方法是不推荐的。到目前为止,我使用的是@Deprecated注释,但我认为这不是一个很好的实践。
这是我的示例代码:
@Deprecated
public String generateToken(UserDetails userDetails) {
return Jwts.builder().setSubject(userDetails.getUsername()).setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 10))
.signWith(SignatureAlgorithm.HS256, KEY).compact();
}
发布于 2022-09-02 00:55:58
按照源代码,您需要翻转变量,以便将键放在第一位:
从0.10.0开始就不再推荐使用{@link #signWith(Key,SignatureAlgorithm)}。此方法将在1.0版本中删除。 @Deprecated signWith(SignatureAlgorithm alg,Key键)抛出InvalidKeyException;
因此,按照不推荐的注释,正确的用法应该是:
signWith(KEY, SignatureAlgorithm)
如果您打算将来升级到1.0版或更新版本的库,那么使用不推荐的方法和@反推荐注释不是解决方案。
https://stackoverflow.com/questions/73576686
复制相似问题