1.创建工程

我们的注册中心,起名为:leyou-registry

选择新建module:

 不要选择骨架:

 然后填写项目坐标,我们的项目名称为leyou-registry:

 选择安装目录,因为是聚合项目,目录应该是在父工程leyou的下面:

2.添加依赖

添加EurekaServer的依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>leyou</artifactId>
        <groupId>com.leyou.parent</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.leyou.common</groupId>
    <artifactId>leyou-registry</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

    </dependencies>
</project>

3.编写启动类

//顶级配置类
@SpringBootApplication
//开启eureka服务端
@EnableEurekaServer
public class WuweiRegistryApplication {

public static void main(String[] args) {
//启动类
SpringApplication.run(WuweiRegistryApplication.class);
}
}

4.配置文件

#修改端口号
server:
  port: 10086

#自定义名字
spring:
  application:
    name: wuwei-regstry

#设置默认的服务端路径
eureka:
  client:
    service-url:
      defaultZone: http://localhost:10086/eureka
    #关闭注册自己
    register-with-eureka: false
    #关闭拉取eureka服务
    fetch-registry: false

  #关闭自我保护模式
  server:
    enable-self-preservation: false

#定期清理无效连接
    eviction-interval-timer-in-ms: 50000

5.项目的结构

目前,整个项目的结构如图:

01-06 05:35