Spring Cloud(2)A Eureka server端 服务注册建立

1. 父项目pom

    <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<type>pom</type>
<scope>provided</scope>
</dependency>

2.Eureka pom

        <dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.1.0.RELEASE</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

3. yml 配置

server:
port: 7001 eureka:
instance:
hostname: localhost #eureka服务器的实例名称
client:
register-with-eureka: false #表示不想注册中心注册自己
fetch-registry: false #表示自己就是注册中心
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置与eureka server交互的地址查询服务

客户端向服务端每30s 发送一次心跳,90s 之后客户端如果没有发送心跳,Service 会去除这个客户端

4.启动类

package com.service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication
@EnableEurekaServer //服务器启动类,接受其他微服务注册进来
public class Dept_Eureka { public static void main(String[] args){
SpringApplication.run(Dept_Eureka.class,args);
}
}
上一篇:ArcGIS发布地图服务时报错Error: ArcGIS Server site is currently being configured by another administrative operation. Please try again later.


下一篇:从微观到宏观,遍历网络安全这幅有向图——By Me