日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Eureka注冊中心之搭建eureka-server

作者:流楚丶格念 更新時間: 2022-07-19 編程語言

文章目錄

  • 1. 搭建eureka-server
    • 1.1 創建eureka-server服務
    • 1.2 引入eureka依賴
    • 1.3 編寫啟動類
    • 1.4 編寫配置文件
    • 1.5 啟動服務

1. 搭建eureka-server

首先大家需要注冊一個中心服務端:eureka-server,這必須是一個獨立的微服務,單獨啟用

1.1 創建eureka-server服務

在你的父工程下,創建一個子模塊:

在這里插入圖片描述

填寫模塊信息:
在這里插入圖片描述

然后填寫服務信息:
在這里插入圖片描述

1.2 引入eureka依賴

引入SpringCloud為eureka提供的starter依賴:

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

在這里插入圖片描述

1.3 編寫啟動類

給eureka-server服務編寫一個啟動類,一定要添加一個@EnableEurekaServer注解,開啟eureka的注冊中心功能:

package com.yyl.eureka;

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

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

1.4 編寫配置文件

編寫一個application.yml文件,內容如下:

server:
  port: 10086
spring:
  application:
    name: eureka-server
eureka:
  client:
    service-url: 
      defaultZone: http://127.0.0.1:10086/eureka

1.5 啟動服務

啟動微服務,然后在瀏覽器訪問:http://127.0.0.1:10086

看到下面結果應該是成功了:
在這里插入圖片描述

原文鏈接:https://blog.csdn.net/weixin_45525272/article/details/125846023

欄目分類
最近更新