Java 将 Jersey 客户端 1.x 升级到 2.x 时 UriBuilder 上的 AbstractMethodError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20079069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:57:07  来源:igfitidea点击:

AbstractMethodError on UriBuilder when upgrading Jersey client 1.x to 2.x

javajersey-clientjersey-2.0

提问by Pepster

We're in the process to upgrade our Web application (running on Tomcat7) from Jersey 1.7 to Jersey 2.4.1. I managed to have the server-side working now, but the JUnit tests which are using jersey-client are throwing the AbstractMethodError: java.lang.AbstractMethodError:

我们正在将 Web 应用程序(在 Tomcat7 上运行)从 Jersey 1.7 升级到 Jersey 2.4.1。我现在设法让服务器端工作,但是使用 jersey-client 的 JUnit 测试抛出了 AbstractMethodError: java.lang.AbstractMethodError:

javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
    at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
    at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:72)
    at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:180)
    at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:69)
    at ******.test.resources.ResourceConfig.getResourceWithCredentialsAt(ResourceConfig.java:144)
    at ******.test.resources.ResourceConfig.getResourceAsUserAt(ResourceConfig.java:99)
    at ******.test.resources.UsersResourceTest.testGetAuthorizedUser(UsersResourceTest.java:251)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access
<!-- Our webapps are tomcat servlets -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- Jersey Container to allow jersey running inside tomcat servlet -->
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <!-- Jersey core dependencies -->
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.bundles</groupId>
            <artifactId>jaxrs-ri</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <!-- Media stuff -->
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-Hymanson</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <!-- Hymanson JSON handling -->
        <dependency>
            <groupId>com.fasterxml.Hymanson.jaxrs</groupId>
            <artifactId>Hymanson-jaxrs-json-provider</artifactId>
            <version>${Hymanson.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.Hymanson.jaxrs</groupId>
            <artifactId>Hymanson-jaxrs-xml-provider</artifactId>
            <version>${Hymanson.version}</version>
        </dependency>
0(ParentRunner.java:53) at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

The project is maintained by maven, here are the pom's dependencies:

项目由maven维护,这里是pom的依赖:

find . -name *.pom -exec grep -Hn jersey {} \;

Apparently I miss a concrete implementation of the UriBuilder class, but I have no clue what dependency I need to add for this. Also -- it works for the server-side, wut!?

显然我错过了 UriBuilder 类的具体实现,但我不知道我需要为此添加什么依赖项。另外 - 它适用于服务器端,哇!?

采纳答案by Pepster

I've found that the enunciatelibrary depends somehow on jersey 1.1.7. This caused parts of my code to compile fine while it was still depending on 1.1.7 API's.

我发现enunciate库在某种程度上取决于 jersey 1.1.7。这导致我的部分代码在仍然依赖 1.1.7 API 的情况下编译得很好。

I found it by doing a find:

我通过查找找到它:

<dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>app</artifactId>
    <version>${project.version}</version>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

...in the ~/.m2 folder on jersey. This can only be done if your app is the only one using maven on your machine.

...在球衣上的 ~/.m2 文件夹中。只有当您的应用程序是唯一在您的机器上使用 maven 的应用程序时,才能完成此操作。

回答by constantlearner

When you see this error, it means UriBuilder is being loaded from other libraries like cxf-2.1.3.jar. Just rename it to z-cxf-2.1.3.jar. It should work fine.In maven find which dependency is bring the jar and use something like this

当您看到此错误时,表示正在从其他库(如 cxf-2.1.3.jar)加载 UriBuilder。只需将其重命名为 z-cxf-2.1.3.jar。它应该可以正常工作。在 maven 中找到哪个依赖项带来了 jar 并使用这样的东西

##代码##