Jdk17 jwt报错 java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
版本
- Spring Boot 3.3.2
- Jdk17
- 原先Jwt0.9.1
解决办法
- 修改maven项目下的pom.xml文件
<!-- Jwt依赖-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
<!-- Jwt依赖-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
</dependency>
<!-- Jwt依赖-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
</dependency>
- 修改Jwt相关代码
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import javax.crypto.SecretKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
@Component
public class JwtTool {
static private Logger log = LoggerFactory.getLogger(JwtTool.class);
private static SecretKey key;
static {
String secertString = "hello,world";
byte[] keyBytes256 = new byte[32];
int encodeNum = Base64.getEncoder().encode(secertString.getBytes(),keyBytes256);
key = Keys.hmacShaKeyFor(keyBytes256);
}
public static String getJwt(HashMap<String, Object> peopleMap) {
try {
String jwt = Jwts.builder()
.setClaims(peopleMap)
.setExpiration(new Date(System.currentTimeMillis()+3600*1000))
.signWith(key)
.compact();
log.info(jwt);
return jwt;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return null;
}
}
public static String parseJwt(String jwt) {
try {
Claims claims = Jwts.parserBuilder()
.setSigningKey(key)
.build()
.parseClaimsJws(jwt)
.getBody();
log.info("解析jwt成功");
return claims.toString();
} catch (Exception e) {
e.printStackTrace();
log.info("解析jwt失败");
return null;
}
}
}
参考
https://blog.csdn.net/u010748421/article/details/107363925
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » Jdk17 jwt报错 java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
发表评论 取消回复