Eureka and Jersey 2.x

自古美人都是妖i 提交于 2021-01-27 07:20:30

问题


I am using Spring Boot and looking for a discovery server. I see that "spring-cloud-starter-netflix-eureka-server" has a dependency on Jersey 1.x which is not an option to use in my environment. There are a couple of threads talking about adding compatibility with Jersey 2.x and some others talking about removing Jersey all together.

However I don't see any links to documentation/code related to either of these options and how to use them. Can someone please point me to the options I have here?

Here are the links I was able to gather on this so far:
https://github.com/Netflix/eureka/issues/600
https://github.com/Netflix/eureka/tree/contrib/jersey2-compatibility/eureka-core-jersey2


回答1:


Below dependencies worked for me. See my pom

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.0.0.RELEASE</version>
    <exclusions>
        <exclusion>
          <groupId>javax.ws.rs</groupId>
          <artifactId>jsr311-api</artifactId>
       </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jersey</artifactId>
</dependency>



回答2:


Spring Boot Jersey starter brings in Jersey 2.x while Spring Cloud Eureka starter brings in eureka client dependency which transitively includes Jersey 1.x.

Basically Spring Boot Jersey starter and Spring Cloud Eureka starter won't play along until eureka client is upgraded to use Jersey 2.x.

Most likely you are getting error(s) like java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

Your options would be:

  • If you want to stick with a JAX-RS impl - Spring Boot CXF Starter -- http://tech.asimio.net/2017/06/12/Implementing-APIs-using-Spring-Boot-CXF-and-Swagger.html

  • Spring Boot + manually configuring Jersey 1.x or Spring MVC Rest -- http://tech.asimio.net/2016/11/14/Microservices-Registration-and-Discovery-using-Spring-Cloud-Eureka-Ribbon-and-Feign.html



来源:https://stackoverflow.com/questions/50400766/eureka-and-jersey-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!