マイクロサービスconstruction_eureka登録センター

1.プロジェクトの構築

親プロジェクトの
pom.xmlファイルを作成します

  1. 梱包方法はpom
  2. srcフォルダを削除
  3. SpringBoot親プロジェクトを追加する
  4. SpringCloudのバージョンを追加します
  5. パッケージング時にテストをスキップするために追加できます
<packaging>pom</packaging>
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
<!--        换成2.3.3版本 eureka会启动失败-->
<!--        <version>2.3.3.RELEASE</version>-->
    </parent>


 <!--springcloud的版本控制-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!--打包的时候跳过测试-->
        <skipTests>true</skipTests>
    </properties>

2つ目は、Eurekaモジュールを作成する

親プロジェクトの下にサブモジュールを作成します

pom.xmlファイル

<?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>***</artifactId>
        <groupId>***</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>******</artifactId>

    <!--eureka的服务端 注册中心-->

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

</project>

application.yml構成ファイル

server:
  port: 7001
eureka:
  instance:
    hostname: 127.0.0.1
  client:
    register-with-eureka: false   #是否将自己注册到eureka中
    fetch-registry: false         #是否从eureka中获取信息
    service-url:
      defaultZone: http://${
    
    eureka.instance.hostname}:${
    
    server.port}/eureka/
spring:
  application:
    name: eureka

メインスタートクラス

package com.mychanggou.goods;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**
 * @author :LiuShihao
 * @date :Created in 2020/8/11 3:36 下午
 * @desc :注册中心启动类
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(EurekaApplication.class);
    }
}

3、他のモジュール

1.各サービスのapplication.ymlに 'を追加します

eureka:
  client:
    service-url:
      defaultZone: http://localhost:6868/eureka

2.eurekaクライアントの依存関係をpom.xmlファイルに追加します

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

3.各サービスのメインスタートアップクラスに@EnableEurekaClient注釈を追加します

eurekaマイクロサービスを開始し、ブラウザでアクセスします。

ここに写真の説明を挿入

おすすめ

転載: blog.csdn.net/DreamsArchitects/article/details/109339043
おすすめ