WildFly 12集成Jersey与JWT时出现NoClassDefFoundError问题求助
解决WildFly 12中Jersey+JWT的NoClassDefFoundError问题
嘿,这个报错我太熟了——Caused by: java.lang.NoClassDefFoundError: io/jsonwebtoken/SignatureAlgorithm 说白了就是你的项目里缺了JJWT(Java JWT)的核心依赖包,JVM找不到SignatureAlgorithm这个类嘛。
看你贴的POM配置,只加了Jackson的JSON处理依赖,JJWT的核心依赖写了一半就断了,这就是问题根源。下面给你一步步解决:
1. 补全JJWT核心依赖
把你没写完的JJWT依赖改成下面这样(推荐用0.9.1版本,和WildFly 12兼容性比较好):
<dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>0.9.1</version> </dependency>
这个版本的JJWT已经内置了Jackson相关依赖,不过你已经单独配置了Jackson 2.9.4,只要版本不冲突就没问题;要是担心冲突,也可以单独引入JJWT的拆分模块:
<dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-api</artifactId> <version>0.9.1</version> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-impl</artifactId> <version>0.9.1</version> <scope>runtime</scope> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-jackson</artifactId> <version>0.9.1</version> <scope>runtime</scope> </dependency>
2. 处理WildFly的类加载冲突
WildFly本身自带了Jackson的版本,很容易和你POM里的版本冲突,导致奇怪的类加载问题。建议在项目的WEB-INF目录下创建jboss-deployment-structure.xml文件,添加如下配置排除WildFly自带的Jackson模块:
<jboss-deployment-structure> <deployment> <exclusions> <module name="com.fasterxml.jackson.core.jackson-core" /> <module name="com.fasterxml.jackson.core.jackson-databind" /> <module name="com.fasterxml.jackson.core.jackson-annotations" /> </exclusions> </deployment> </jboss-deployment-structure>
最后验证一下
- 执行
mvn clean install重新构建项目 - 把打好的包部署到WildFly 12上启动
- 测试你的JWT接口,应该就不会再报这个错了
内容的提问来源于stack exchange,提问作者Felipe Flores
相关产品推荐
相关产品推荐

