下图是个人整理的SpringCloud系列各个组件的功能介绍,可以点击放大看,仅供参考:
简介:
Spring Cloud Eureka是Spring Cloud Netflix项目下的服务治理模块。而Spring Cloud Netflix项目是Spring Cloud的子项目之一,主要内容是对Netflix公司一系列开源产品的包装,它为Spring Boot应用提供了自配置的Netflix OSS整合。通过一些简单的注解,开发者就可以快速的在应用中配置一下常用模块并构建庞大的分布式系统。它主要提供的模块包括:服务发现(Eureka),断路器(Hystrix),智能路由(Zuul),客户端负载均衡(Ribbon)等
注意事项:
1、SpringBoot版本一定要和SpringCloud版本一定要匹配(详情阅读https://vsalw.com/1209.html)。
2、注意端口冲突
业务场景:
这个是服务注册发现的第一步,只是建立了一个服务注册中心,其他服务能够进行注册。为了方便监控,此处也加入了actuator的依赖包,关于actuator使用详情参阅:https://blog.csdn.net/WYA1993/article/details/80540981
第一步、添加依赖,注意此处SpringBoot版本是1.4.3.RELEASE
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<!--引入Eureka_Server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!--加入监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 引入spring cloud的依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
第二步、配置配置文件
server.port=8899
#表示是否将自己注册到Eureka Server,默认为true。由于当前这个应用就是Eureka Server,故而设为false
eureka.client.register-with-eureka=false
#表示是否从Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false
eureka.client.fetch-registry=false
#设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://localhost:8761/eureka ;多个地址可使用 , 分隔
eureka.client.serviceUrl.defaultZone=http://localhost:8899/eureka/
#应用名称
eureka.instance.appname=EurekaServer
#Actuator配置是否允许关闭程序,POST方法
endpoints.shutdown.enabled=true
第三步、在启动类上加注解 @EnableEurekaServer
启动如下图:源码下载:EurekaServer