java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder when started Tomcat Server(java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder 启动 Tomcat 服务器时)
问题描述
我正在使用 Jersey 和 Maven 在 Java 中构建 REST API.我使用 Tomcat 9 作为我的服务器.在我今天尝试安装 RestAssured、 Hamcrest、 和 JUnit 之前,一切正常.突然间,我所有的端点都抛出了 500 个内部服务器错误.500错误的根本原因是java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder.
I am building REST API in Java with Jersey and Maven. I used Tomcat 9 as my server. Everything works fine until I tried to install RestAssured, Hamcrest, and JUnit today. Suddenly all of my endpoints threw out 500 Internal server errors. The root cause of the 500 error is java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder.
这两个小时我做了什么:
What I have done this 2 hours:
- 我曾尝试在 google 上找到此类:
org/glassfish/jersey/internal/inject/Binder
,但无济于事. - 我曾尝试卸载 RestAssured、Hamcrest 和 JUnit,但没有帮助.
- I have tried to find this class:
org/glassfish/jersey/internal/inject/Binder
on google, but no avail. - I have tried to uninstall RestAssured, Hamcrest, and JUnit but it didn't help.
这个问题让我很沮丧.知道为什么会发生此错误吗?提前致谢!
This problem makes me frustrated. Any idea why this errors happened? Thanks in advance!
这是服务器日志的摘录:
Here is the excerpt of the server log:
严重:为 servlet Jersey Web 应用程序 java.lang.ClassNotFoundException 分配异常:org.glassfish.jersey.internal.inject.Binder在org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)在org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)在 org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178)在 org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370)在 javax.servlet.GenericServlet.init(GenericServlet.java:158)在 org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)在 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)在 org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779)在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)在 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)在 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)在 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)在 org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)在 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1368)在 org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)在 java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(未知来源)在 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)在 java.lang.Thread.run(Unknown Source)
SEVERE: Allocate exception for servlet Jersey Web Application java.lang.ClassNotFoundException: org.glassfish.jersey.internal.inject.Binder at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1368) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
下面是我的 pom.xml
文件:(带有 RestAssured、Hamcrest 和 JUnit)
Below is my pom.xml
file: (with RestAssured, Hamcrest, and JUnit)
下面是我的 web.xml 文件:
Below is my web.xml file:
下面是我的项目结构:
邮件列表项目结构
推荐答案
核心 Jersey
与导入的 Jersey
扩展库之一之间很可能存在版本不匹配Binder
类.确保所有与 Jersey 相关的模块都有明确的版本(并且它们相互匹配).或者更好的是,通过导入 jersey-bom 来修复您的版本.例如:
Very likely there is a version mismatch between core Jersey
and one of the Jersey
extension libraries that imports that Binder
class. Make sure all Jersey-related modules have explicit versions (and they match each other). Or even better, fix your versions by importing the jersey-bom. E.g.:
之后,您的主要 <dependencies>
部分可能会省略版本.
After which your main <dependencies>
section may omit the versions.
这篇关于java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder 启动 Tomcat 服务器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!