NoSuchMethodError: MultivaluedMap.addAll in Jersey Client

前端 未结 3 1971
予麋鹿
予麋鹿 2020-12-03 13:29

I\'m trying to use Jersey Client to simulate HTTP requests to my web service. I tried to implement the simple example from the documentation. Here\'s my short code:

相关标签:
3条回答
  • 2020-12-03 14:00

    In my case this looks to be an incompatibility issue with Jersey Client and Jersey Core. I got past it by disabling the client:

    <dependencies>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.2</version>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpcore</artifactId>
                <version>4.4.4</version>
            </dependency>
            <dependency>
                <groupId>pl.pragmatists</groupId>
                <artifactId>JUnitParams</artifactId>
                <version>1.0.5</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.12</version>
                <scope>test</scope>
            </dependency>
            <!--<dependency>-->
                <!--<groupId>com.sun.jersey</groupId>-->
                <!--<artifactId>jersey-client</artifactId>-->
                <!--<version>1.19</version>-->
            <!--</dependency>-->
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi-ooxml</artifactId>
                <version>3.14</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.4</version>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>2.45.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.8</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.saucelabs</groupId>
                <artifactId>sauce_junit</artifactId>
                <version>2.1.18</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax.ws.rs</groupId>
                <artifactId>javax.ws.rs-api</artifactId>
                <version>2.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.core</groupId>
                <artifactId>jersey-client</artifactId>
                <version>2.16</version>
            </dependency>
        </dependencies>
    
    0 讨论(0)
  • 2020-12-03 14:08

    This looks like an inconsistency pertaining to the JAX-RS API version (which contains the MultiValuedMap).

    You are using client jersey-client v2.2, which is compiled against v2.0 of the JAX-RS API. But your runtime states to run with Java EE 6, which defines JAX-RS API v1.1. So your code expects v2.0 of the JAX-RS API, but gets v1.1 at runtime.

    This is the MultiValuedMap API for Java EE 6:

    http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/MultivaluedMap.html (no addAll method).

    And for Java EE 7:

    http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/MultivaluedMap.html (this one includes the addAll method).

    As you are using Java EE 6, you should be using jersey-client v1.8, not 2.2. Or you should be including the Java EE 7 API in your runtime classpath, and not 6.

    0 讨论(0)
  • 2020-12-03 14:09

    The offending class comes from this dependency

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    

    It has jax-rs 1.1 core classes inside, specifically MultivaluedMap interface without addAll method.

    Either disable it (It seems you can if only using Jersey), or upgrade to version to 7.0

    0 讨论(0)
提交回复
热议问题