Spring Cloud是当前煊赫一时的微服务开发框架。它的功能强大,组件丰富,设计优雅。目前Spring Cloud还在不断发展之中。java
Spring Cloud即将发布Spring Cloud Edgware
版本。该版本解决了很多Bug,新增了很多新特性,本系列博客将为你们详细阐述在Spring Cloud Edgware中新增的特性。git
为了让描述更加的贴合实际,本文将结合笔者所在团队遇到的实际状况进行讲解。github
Eureka服务器与客户端之间默认使用Jersey 1.x
进行基于HTTP协议的交互。然而咱们团队,需使用docker-client
(https://github.com/docker-java/docker-java) 。这货只支持Jersey 2.x
,而Jersey 1.x与2.x并不兼容。spring
因而,咱们团队面临以下几种选择:docker
eureka-client-jersey2
模块,即便用Jersey 2.x
来代替Jersey 1.x
https://github.com/Netflix/eureka/tree/master/eureka-client-jersey2 。然而,这种方式不够稳妥,缘由是eureka-client-jersey2
是由社区提供,并不是由Eureka官方团队维护,而且已经好久不更新了。docker-client
,使用其余的Docker客户端,例如https://github.com/spotify/docker-client (该项目支持Jersey 1.x以及Jersey 2.x)。Spring Cloud Netflix
到1.4.x,即:Spring Cloud Edgware
【笔者认为的最佳方案】。本文探讨的就是在Spring Cloud Edgware
中Eureka的点点滴滴。apache
Spring Cloud Edgware
中,Jersey并不是必选。可为Eureka Client禁用掉Jersey,转而使用咱们想要的HTTP客户端,例如RestTemplate。只需将Jersey的包从依赖中删除,Spring Cloud就会自动配置一个基于Spring RestTemplate
的传输客户端。操做以下:服务器
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <exclusions> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> </exclusion> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> </exclusion> <exclusion> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-apache-client4</artifactId> </exclusion> </exclusions> </dependency>
简单的操做后,有两个好处:框架
详见:https://github.com/spring-cloud/spring-cloud-netflix/issues/1849 。简单来讲,就是Eureka提供了一个抽象,容许用户为Eureka Client定制本身的HTTP客户端,而不像老版本,强制使用Jersery。微服务