0
点赞
收藏
分享

微信扫一扫

Springboot 整合 SpringCloud组件-Eureka 注册中心 EurekaServer (一)


 Eureka ,我们简单用一张图介绍:

Springboot 整合 SpringCloud组件-Eureka  注册中心 EurekaServer (一)_服务器

接下来开始整合:

 首先创建一个springboot项目,eureka:

 

Springboot 整合 SpringCloud组件-Eureka  注册中心 EurekaServer (一)_注册中心_02

(创建时勾选上 Eureka Server依赖,我们这里选用的springcloud版本是:Finchley.RELEASE)

pom.xml中相关的组件依赖是:

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

然后是application.yml配置文件:

 

#指定服务的端口
server:
port: 8761

eureka:
instance:
hostname: localhost
client:
#是否注册自身到eureka服务器
registerWithEureka: false
#是否从eureka服务器获取注册信息
fetchRegistry: false
#设置eureka服务器所在的地址,查询服务和注册服务都需要依赖这个地址
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# server:
#1.关闭注册中心自我保护机制
# enable-self-preservation: false
#2.注册中心清理间隔(单位毫秒,默认60*1000
# eviction-interval-timer-in-ms: 10000
spring:
application:
#设置服务名
name: eurka-server

以上的配置项详解已经做了相关注释(eureka.client.registerWithEureka:false和fetchRegistry:false来表明自己是一个Eureka Server,不需要注册到服务器)。

  最后,在启动类上开启注册中心Server注解 @EnableEurekaServer:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}

}

 到此,springboot整合注册中心已经完成,我们运行下项目,访问 ​​http://localhost:8761/​​  :

Springboot 整合 SpringCloud组件-Eureka  注册中心 EurekaServer (一)_注册中心_03

 

OK,可以看到Eureka注册中心已经成功部署, 其中:

这里显示的是,暂无任何服务注册信息

Springboot 整合 SpringCloud组件-Eureka  注册中心 EurekaServer (一)_Springcloud_04

 


举报

相关推荐

0 条评论