基本springboot 2.0版本 spring-cloud的使用(注册中心)

匿名 (未验证) 提交于 2019-12-02 20:37:20

Spring Cloud与Spring Boot版本匹配关系

Spring CloudSpring Boot
Finchley 兼容Spring Boot 2.0.x,不兼容Spring Boot 1.5.x
Dalston和Edgware 兼容Spring Boot 1.5.x,不兼容Spring Boot 2.0.x
Camden 兼容Spring Boot 1.4.x,也兼容Spring Boot 1.5.x
Brixton 兼容Spring Boot 1.3.x,也兼容Spring Boot 1.4.x
Angel 兼容Spring Boot 1.2.x

从Spring Cloud与Spring Boot版本匹配关系可以看出,如果项目使用的spring boot 版本在 2.0以上,那么必须使用spring cloud 版本 为

Finchley.RELEASE版本 这个版本与以前的D版本有一些区别,下面主要讲的就是spring cloud F版本的简单使用

服务的注册与发现Eureka(Finchley版本)

Eureka是一个基于REST(Representational State Transfer)的服务,主要用于AWS cloud, 提供服务定位(locating services)、负载均衡(load balancing)、故障转移(failover of middle-tier servers)。我们把它叫做Eureka Server. Eureka也提供了基于Java的客户端组件,Eureka Client,内置的负载均衡器可以实现基本的round-robin负载均衡能力。在Netflix,一个基于Eureka的更复杂的负载均衡器针对多种因素(如流量、资源利用率、错误状态等)提供加权负载均衡,以实现高可用(superior resiliency).

下面是简单的使用

<dependencies>   <dependency>      <groupId>org.springframework.cloud</groupId>      <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>   </dependency></dependencies>

然后就是配置文件信息

spring.application.name=eureka-server server.port=1001  eureka.instance.hostname=localhost  #表示是否将自己注册到Eureka Server上,默认为true eureka.client.register-with-eureka=false  #表示是否从Eureka Server上获取注册信息,默认为true eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

接下来java代码,开启EnableEurekaServer注解,

然后启动项目,去往网址,一个服务注册中心完成

github地址: https://github.com/yihec/springCloud

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