1.注册中心的搭建

1. pom文件中引入相关的包

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>

2. 配置文件的编写

server:
port: 1066
spring:
application:
name: cloud-eureka-server
eureka:
client:
fetch-registry: false
register-with-eureka: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
instance:
hostname: 127.0.0.1
server:
enable-self-preservation: false
eviction-interval-timer-in-ms: 5000

3.启动类加@EnableEurekaServer注解


@EnableEurekaServer
@SpringBootApplication
public class CloudEurekaServerApplication {

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

}

2.服务提供者的搭建

1. pom文件中引入相关的包

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>

2. 配置文件的编写

server:
port: 8094

spring:
application:
name: eurekaClient
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:1066/eureka/
eureka-server-read-timeout-seconds: 180

3.启动类加@EnableEurekaClient 注解

@EnableEurekaClient
@SpringBootApplication
public class CloudService1Application {

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

}


简单的Eureka就这么搭建完了,消费者的搭建与服务提供者类似,这里就不详细写了。需要注意的是Spring Boot2.0以上,不支持1.4版本的Eureka,若没注意,消费者的使用中会出现各种问题。