创建一个spring cloud 项目
创建父工程
IDEA创建maven 工程 生成空的maven项目即可
1.pom文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Eureka Server 代码实现
(//在父类工程中创建点击父工程名称右击在父工程下创建module)
1.配置XML
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
</dependencies>
2.在子项目创建application.yml 文件
server:
port: 8761
# 是否注册本身 false 指的是不注册
# 是否获取其他Eureka Server服务的数据
# 注册中心的访问地址
eureka:
client:
register-with-eureka: false//是否要注册它
fetch-registry: false //是否要获取其他eureka节点的数据;
service-url:
defaultZone: http://localhost:8761/eureka/
3.创建启动类
package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String [] args){
SpringApplication.run(EurekaServerApplication.class,args);
}
}
注解说明:
@spring boot application : 声明该类是Spring boot 服务的入口
@Enable Eureka Server : 声明该类是一个Eureka Server 微服务, 提供服务注册和服务发现功能起注册中心功能
//以上注册中心就已经搭建完成,下一步,我们就要进行client 服务消费者,提供者的编写搭建。