1、本篇只搭建eureka提供服务注册

springCloud-eureka篇一服务注册中心_xml

1、创建一个meven(parent)项目,作为父工程管理依赖

他的pom文件

<?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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath></relativePath>
    </parent>
    <packaging>pom</packaging>
    <groupId>com.xue</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR2</spring-cloud.version>
        <spring-boot.version>2.1.0.RELEASE</spring-boot.version>
        <akka.version>2.5.21</akka.version>
        <qinwell-common.version>3.0.0-SNAPSHOT</qinwell-common.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

2、parent上新建一个module,eureka-server.

1、pom.xml 父类是parent,已经做好管理,所以版本信息可以不加

<parent> <groupId>com.xue</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>

2、启动类上开启eureka注册中心

@EnableEurekaServer   //***
@SpringBootApplication
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

3、在yml配置注册中心信息

server:
  port: 8761
eureka:
  instance:
    hostname: peer1  //我做了hosts映射 ,你要写localhost
  client:
    service-url:
      defaultZone: http://peer1:8761/eureka/
    register-with-eureka: false //不做eureka集群信息,故取消自己向自己注册
    fetch-registry: false    // 禁用抓取注册信息

启动访问 http://peer1:8761/eureka/即可启用Eureka注册