java.lang.NoSuchMethodError(org.glassfish.jersey.server.ApplicationHandler。)

黄沙百战穿金甲,不破楼兰终不还。这篇文章主要讲述java.lang.NoSuchMethodError:org.glassfish.jersey.server.ApplicationHandler。相关的知识,希望能为你提供帮助。
我一直在尝试调试这个问题,并搜索SO和其他网站,我一直无法找到解决方案。我已经在我的pom.xml中检查了所有版本的依赖项,并确保它们与grizzly2兼容,并且我还验证了它正在导入。但是,java仍在运行时打印出此错误:

Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.< init> (Ljavax/ws/rs/core/Application; Lorg/glassfish/hk2/utilities/Binder; )V at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.< init> (GrizzlyHttpContainer.java:334) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:122) at com.kyrahosting.daemon.Main.startServer(Main.java:30) at com.kyrahosting.daemon.Main.main(Main.java:34)

【java.lang.NoSuchMethodError(org.glassfish.jersey.server.ApplicationHandler。)】这是我的pom.xml:4.0.0
< groupId> com.kyrapanel.daemon< /groupId> < packaging> jar< /packaging> < name> KyraPanel Daemon< /name> < artifactId> KyraDaemon< /artifactId> < version> 1.0-SNAPSHOT< /version> < dependencyManagement> < dependencies> < dependency> < groupId> org.glassfish.jersey< /groupId> < artifactId> jersey-bom< /artifactId> < version> ${jersey.version}< /version> < type> pom< /type> < scope> import< /scope> < /dependency> < /dependencies> < /dependencyManagement> < dependencies> < dependency> < groupId> org.glassfish.jersey.containers< /groupId> < artifactId> jersey-container-grizzly2-http< /artifactId> < version> 2.9.1< /version> < /dependency> < dependency> < groupId> org.glassfish.grizzly< /groupId> < artifactId> grizzly-http-all< /artifactId> < version> 2.3.30< /version> < /dependency> < dependency> < groupId> org.glassfish.jersey.core< /groupId> < artifactId> jersey-server< /artifactId> < version> 2.25.1< /version> < /dependency> < dependency> < groupId> org.glassfish.jersey.containers< /groupId> < artifactId> jersey-container-servlet-core< /artifactId> < version> 2.25.1< /version> < /dependency> < dependency> < groupId> org.seleniumhq.selenium< /groupId> < artifactId> selenium-java< /artifactId> < version> 3.3.1< /version> < /dependency> < /dependencies> < build> < finalName> ${project.artifactId}< /finalName> < plugins> < !-- any other plugins --> < plugin> < artifactId> maven-assembly-plugin< /artifactId> < executions> < execution> < phase> package< /phase> < goals> < goal> single< /goal> < /goals> < /execution> < /executions> < configuration> < descriptorRefs> < descriptorRef> jar-with-dependencies< /descriptorRef> < /descriptorRefs> < /configuration> < /plugin> < plugin> < groupId> org.apache.maven.plugins< /groupId> < artifactId> maven-compiler-plugin< /artifactId> < version> 2.5.1< /version> < inherited> true< /inherited> < configuration> < source> 1.7< /source> < target> 1.7< /target> < /configuration> < /plugin> < plugin> < groupId> org.codehaus.mojo< /groupId> < artifactId> exec-maven-plugin< /artifactId> < version> 1.2.1< /version> < executions> < execution> < goals> < goal> java< /goal> < /goals> < /execution> < /executions> < configuration> < mainClass> com.kyrahosting.daemon.Main< /mainClass> < /configuration> < /plugin> < /plugins> < /build> < properties> < jersey.version> 2.17< /jersey.version> < project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding> < /properties>


任何帮助将不胜感激!
答案不要混合你的泽西版本
< dependency> < groupId> org.glassfish.jersey.containers< /groupId> < artifactId> jersey-container-grizzly2-http< /artifactId> < version> 2.9.1< /version> < /dependency> < dependency> < groupId> org.glassfish.jersey.core< /groupId> < artifactId> jersey-server< /artifactId> < version> 2.25.1< /version> < /dependency> < dependency> < groupId> org.glassfish.jersey.containers< /groupId> < artifactId> jersey-container-servlet-core< /artifactId> < version> 2.25.1< /version> < /dependency>

哪一个不同?修理它。
并摆脱这一点
< dependency> < groupId> org.glassfish.grizzly< /groupId> < artifactId> grizzly-http-all< /artifactId> < version> 2.3.30< /version> < /dependency>

jersey-container-grizzly2-http已经为Grizzly提供了所需的一切。
顺便说一下,错误没有说“GrizzlyHttpServerFactory不存在”。它说没有这样的方法(在这种情况下是构造函数)
public ApplicationHandler(Application application, Binder binder) {}

这就是你读这个的方式
java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.< init> (Ljavax/ws/rs/core/Application; Lorg/glassfish/hk2/utilities/Binder; )V

混合版本时你会得到这个错误的原因是因为说Jersey 2.25.1中的某些类试图调用上面提到的构造函数。但在版本2.9.1中,此构造函数不存在。说它没有添加到更高版本。但是在加载类时,加载了来自2.9.1的ApplicationHandler,而不是2.25.1中的ApplicationHandler。所以现在你加载了错误的< dependency> < groupId> org.eclipse.jetty< /groupId> < artifactId> jetty-server< /artifactId> < version> 9.4.8.v20171121< /version> < /dependency> < dependency> < groupId> org.eclipse.jetty< /groupId> < artifactId> jetty-servlet< /artifactId> < version> 9.4.8.v20171121< /version> < /dependency> < dependency> < groupId> org.eclipse.jetty< /groupId> < artifactId> jetty-webapp< /artifactId> < version> 9.4.8.v20171121< /version> < /dependency> < dependency> < groupId> javax.ws.rs< /groupId> < artifactId> javax.ws.rs-api< /artifactId> < version> 2.1< /version> < /dependency> < dependency> < groupId> org.glassfish.jersey.bundles.repackaged< /groupId> < artifactId> jersey-guava< /artifactId> < version> 2.26-b03< /version> < /dependency> 版本。因此错误; 没有这样的构造函数。
另一答案在2017年12月,这组Maven依赖项对我来说很好用RS启动Jetty。
qazxswpoi


    推荐阅读