question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support jersey 2 for eureka

See original GitHub issue

Using Jersey for the REST layer in a project, I’ve got a dependency conflict when using Spring Cloud as follow:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-parent</artifactId>
                <version>Brixton.M4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zuul</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-security</artifactId>
          <scope>runtime</scope>
      </dependency>

The Spring Boot Jersey dependency org.springframework.boot:spring-boot-starter-jersey:jar:1.3.2.RELEASE is used.

The error is

java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:331) ~[jersey-server-2.22.1.jar:na]
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390) ~[jersey-container-servlet-core-2.22.1.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:172) ~[jersey-container-servlet-core-2.22.1.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:364) ~[jersey-container-servlet-core-2.22.1.jar:na]
    at javax.servlet.GenericServlet.init(GenericServlet.java:158) ~[tomcat-embed-core-8.0.30.jar:8.0.30]

and it comes from the fact that both

  • javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
  • javax.ws.rs:jsr311-api:jar:1.1.1:runtime are present in the classpath.

spring-cloud-starter-zuul includes jsr311-api.jar from its ribbon-httpclient dependency

+- com.netflix.ribbon:ribbon-httpclient:jar:2.1.0:compile
    [INFO] |  |  |  +- com.sun.jersey:jersey-client:jar:1.19:runtime
    [INFO] |  |  |  |  \- com.sun.jersey:jersey-core:jar:1.19:runtime
    [INFO] |  |  |  |     \- javax.ws.rs:jsr311-api:jar:1.1.1:runtime
    [INFO] |  |  |  \- com.sun.jersey.contribs:jersey-apache-client4:jar:1.19:runtime

I solved it by excluding jersey-client like this

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-parent</artifactId>
                <version>Brixton.M4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-zuul</artifactId>
          <exclusions>
                <exclusion>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-client</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jersey.contribs</groupId>
                    <artifactId>jersey-apache-client4</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-security</artifactId>
            <scope>runtime</scope>
        </dependency>

It works when testing Zuul manually but I’m not sure it would under all conditions.

It’s heavy handed but I figure I already have a much newer jersey client org.glassfish.jersey.core:jersey-client:jar:2.22.1:compile included with Spring Boot Jersey.

Why would ribbon use older Jersey client dependency? Is there any reason it wouldn’t work with the newest org.glassfish.jersey.core:jersey-client:jar:2.22.1 ??

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
voorcommented, Oct 26, 2016

Update in this thread, looks like Eureka Client 1.6 will be compatible: https://github.com/Netflix/eureka/pull/821

0reactions
jlelong-onepointcommented, Nov 19, 2020

The migration path is to not use Jersey 1.x, I guess (https://cloud.spring.io/spring-cloud-netflix/multi/multi__service_discovery_eureka_clients.html#_eurekaclient_without_jersey). And I guess to not use Ribbon.

I had wrongly guess that was not supported as this ticket is open. On my side i have also exclude the jsr311 (jax-rs 1) dependency as my point was to avoid conflict with jax-rs 2. Eureka client and core explicitly depend on it in addition to jersey.

For reference my final gradle configuration is :

    implementation('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') {
        exclude group: 'com.sun.jersey'
        exclude module: 'jsr311-api'
    }

We have now to test in order to assure compatibility between Eureka and jaxrs 2.

Thanks a lots for your help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eureka and Jersey 2.x - Stack Overflow
Spring Boot Jersey starter brings in Jersey 2.x while Spring Cloud Eureka starter brings in eureka client dependency which transitively includes ...
Read more >
Blogs - SpringBoot, Jersey & Eureka - A.Stoisavljevic
Aleksandar Stoisavljevic in Development 20 minute read. A story about how to setup SpringBoot, Jersey & Eureka. Jersey 2.x and SpringCloud ...
Read more >
eureka-client-jersey2 : 1.10.0 - Maven Central
Official search by the maintainers of Maven Central Repository.
Read more >
1. Service Discovery: Eureka Clients - Spring Cloud
Eureka is the Netflix Service Discovery Server and Client. ... By default, EurekaClient uses Jersey for HTTP communication. ... Service 1 in Zone...
Read more >
Eureka! Module - Drumthwacket, the Official Residence of the ...
Barth, author of A History of Inventing in New Jersey, for her assistance in writing the inventor summaries found in Lesson 2 and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found