jwc令牌报错生成失败
源代码
// 生成jwt令牌 @Test public void testGenJwt(){ Map<String, Object> claims = new HashMap<>(); //存储测试数据 claims.put("id",1); claims.put("name","ZTZGTEDXT"); String jwt = Jwts.builder() .signWith(SignatureAlgorithm.HS256, "itheima") //设置签名算法 .setClaims(claims) //自定义内容(载荷部分) .setExpiration(new Date(System.currentTimeMillis() + 3600 * 1000)) //有效期为1h,new Date()当前时间,System.currentTimeMillis()当前时间的毫秒值 .compact(); System.out.println(jwt); }
版本不适配,更改版本后:
jdk:17
pom.xml
<!-- jwt令牌依赖-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
</dependency>
出现新报错

嘶……这是,太短了?

将signWith部分更改到50字符后,又出现新报错


补充依赖为
<!-- jwt令牌依赖-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.5</version>
</dependency>
<dependency> <!-- -->
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.5</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>
加载,再次运行代码

令牌生成成功
——————
无关:jwt官网地址: https://jwt.io/

浙公网安备 33010602011771号