亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Spring Cloud Eureka 服務注冊與發現中心

標簽:
Spring Cloud

Eureka 介绍

Eureka 是 Spring Cloud 的组件 Spring Cloud Netflix 中的一个模块,负责完成对微服务架构的服务治理功能。

Eureka 服务的三个角色

Eureka 服务端

Eureka 提供的服务端,负责服务的注册与发现功能,一般称为 eureka server。

服务提供者

提供服务的应用,将自己提供的服务注册到 Eureka,以供其他应用发现。

服务消费者

消费者应用从服务注册中心获取提供的服务列表, 从而使消费者可以知道去何处调用其所需要的服务。

引入依赖

pom.xml 中主要添加依赖 spring-cloud-starter-netflix-eureka-server

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

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

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
  </parent>

  <groupId>cloud.antoniopeng</groupId>
  <artifactId>hello-spring-cloud-dependencies</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <!-- Environment Settings -->
    <java.version>1.8</java.version>
  </properties>

  <dependencyManagement>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Finchley.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

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

相关配置

application.yml 中添加以下配置

spring:
  application:
    # 指定唯一服务名称以供调用
    name: hello-spring-cloud-netflix-eureka

server:
  # 指定服务器端口号
  port: 8761

eureka:
  instance:
    # 指定服务器IP地址
    hostname: localhost
  client:
    # 声明为 Eureka Server , 否则会被认为是Eureka Client
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      # 指定服务器完整路径
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

Application 入口类中加上注解 @EnableEurekaServer 开启 Eureka 服务

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

启动项目

访问 Eureka 操作界面 http://localhost:8761

《Spring Cloud Eureka 服务注册与发现中心》

该页面目前没有显示任何服务,因为我们还没有将其它服务注册到 Eureka 中。

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
JAVA開發工程師
手記
粉絲
0
獲贊與收藏
10

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消