![](/img/trans.png)
[英]Spring Boot - Jwts.builder Cannot resolve method 'signWith()’
[英]What substitute can I use for Java Spring's Jwts.signWith() deprecated method?
我需要在 mi API 中使用 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();
}
根據源代碼,您需要翻轉變量,以便 Key 首先出現:
@deprecated since 0.10.0: 改用 {@link #signWith(Key, SignatureAlgorithm)}。 此方法將在 1.0 版本中刪除。
@Deprecated JwtBuilder signWith(SignatureAlgorithm alg, Key key) throws InvalidKeyException;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.