SpringBoot简化了Spring的配置及组件信息,Spring Cloud是基于SpringBoot的基础上,是一系列框架的有序集合,是微服务系统架构的一站式解决方案。Spring Cloud官网Level up your Java code and explore what Spring can do for you.https://spring.io/projects/spring-cloud
Spring Cloud中文网https://www.springcloud.cc/
一、版本介绍
Spring Cloud版本不是数字,而是一些英国伦敦地铁站的站名,比如Greenwich格林威治,每个版本如果积累的bug很多又会发布一个Service Release小版本,简称SR版本会按数字递增;Spring Cloud与Spring Boot版本要对应,官网上会有对应说明。
二、Eureka介绍
Eureka是Netflix开发的服务发现框架,基于rest的服务,SpringCloud将其集成在Spring-cloud-netflix中,实现服务发现功能,Zookeeper、Consul、Eureka等都可以充当服务发现组件。
Eureka与Zookeeper区别在于对CAP原则的支持不同,Eureka支持AP原则,强调可用性;Zookeeper支持CP原则,强调一致性;其中P表示分区容错性。
三、Eureka工程创建
1.idea中创建Spring Initializr工程,引入以下依赖
创建完成后可以看到Springboot与SpringCloud对应版本信息
2.配置yml文件
server:
port: 8003
eureka:
instance:
hostname: localhost # eureka主机名称
client:
register-with-eureka: false #是否向注册中心注册自己
fetch-registry: false # 此客户端是否可以获取eureka注册信息
service-url: #暴露服务中心地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
3.启动类开启eureka服务可用注解
@EnableEurekaServer //开启Eureka服务
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
4.开启启动类效果