1.加入eureka-server启动器
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
2.添加application.yml中添加相关配置
server:
port: 10086
spring:
application:
name: xxxx-registry # 服务名称
eureka:
client:
service-url:
defaultZone: http://localhost:10086/eureka # 注册中心地址
register-with-eureka: false # 禁止自己注册到自己
fetch-registry: false # 屏蔽注册信息
server:
# 自我保护模式,当出现网络分区故障、频繁的开启关闭客户端、eureka在短时间内丢失过多客户端时,会进入自我保护模式,即一个服务长时间没有发送心跳,eureka也不会将其删除,默认为true
enable-self-preservation: false
# eureka server清理无效节点的时间间隔,默认60000毫秒,即60秒
eviction-interval-timer-in-ms: 10000
- 启动类上添加注解
@SpringBootApplication
@EnableEurekaServer //表明是注册中心
public class RegistryApplication {
public static void main(String[] args) {
SpringApplication.run(RegistryApplication.class);
}
}