You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tomcat9下Jersey API报NoSuchMethodError:SignatureAlgorithm.getMinKeyLength()

解决方案:JWT NoSuchMethodError 问题修复

问题根源

你的pom.xml中同时引入了JJWT 0.11.2的拆分模块(jjwt-api/jjwt-impl/jjwt-jackson)和JJWT 0.9.1的聚合包(jjwt),导致版本冲突:

  • 0.11.x版本的Keys.hmacShaKeyFor()方法会调用SignatureAlgorithm.getMinKeyLength()校验密钥强度
  • 但0.9.1版本的SignatureAlgorithm类不存在该方法,类加载器优先加载了旧版本类,因此触发NoSuchMethodError

修复步骤

  1. 移除冲突的旧版本依赖
    删除pom.xml中0.9.1版本的jjwt依赖项,保留0.11.2版本的三个拆分模块即可。修改后的pom.xml依赖片段如下:
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-api</artifactId>
    <version>0.11.2</version>
</dependency>
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-impl</artifactId>
    <version>0.11.2</version>
    <scope>runtime</scope> <!-- 可选,明确标记为运行时依赖 -->
</dependency>
<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt-jackson</artifactId>
    <version>0.11.2</version>
</dependency>
  1. 清理并重新构建项目
  • 执行Maven命令:mvn clean install,清理旧依赖缓存并重新构建
  • 检查Tomcat的webapps/你的项目/WEB-INF/lib目录,确保无残留0.9.1版本的jjwt-*.jar文件,如有则手动删除
  1. 验证修复
    重启Tomcat并调用生成JWT的接口,确认错误不再出现

内容的提问来源于stack exchange,提问作者Eric Malalel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:36:20