java.lang.NoSuchMethodError : org. glassfish.jersey.server.ApplicationHandler.<初始化>

标签 java jersey grizzly

我一直在尝试调试这个问题,并且搜索 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)

这是我的 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>

任何帮助将不胜感激!

最佳答案

不要混用 Jersey 版本

<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 版本。因此错误;没有这样的构造函数。

关于java.lang.NoSuchMethodError : org. glassfish.jersey.server.ApplicationHandler.<初始化>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43642236/

相关文章:

java - Grizzly HttpServer 中的连接限制

java - 单击它时获取动态生成的 TextView 的文本

java - 当有人未​​能输入正确的密码时,如何使对话框显示?

java - Jetty+Jersey,意外异常: Asynchronous processing not supported on Servlet 2. x容器

java - 使用 Jersey Client 的 PATCH 请求

java - 无法将 JSON 对象发送到 Rest Web 服务

java - 在 Grizzly 中配置 session cookie 名称

jsf - 返回多个大响应时Servlet抛出GF4不正确超时异常(请求)

java - 由 : java. lang.IndexOutOfBoundsException : Invalid index 8, 大小为 8 引起

java - 整数和的总值不等于计算值