Eureka注册中心的作用就是管理服务
-
新建项目
选择下图依赖自动导入eureka的依赖
-
配置文件application.properties
## server server.port=8888 ##eureka #指定环境 eureka.environment=work # 设置是否将自己作为客户端注册到注册中心(缺省true) # 这里为不需要(查看@EnableEurekaServer注解的源码,会发现它间接用到了@EnableDiscoveryClient) eureka.client.register-with-eureka=false # 设置是否从注册中心获取注册信息(缺省true) # 因为这是一个单点的EurekaServer,不需要同步其它EurekaServer节点的数据,故设为false eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/ #是否开启自我保护模式,默认为true。 eureka.server.enable-self-preservation=true #续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms) eureka.server.eviction-interval-timer-in-ms=10000
-
启动类
package com.example.eureka; 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); } }
-
运行项目,显示下面页面则表示成功