springcloud(第三篇)springcloud eureka 服务注册与发现

本文介绍了Spring Cloud Eureka作为服务发现和注册的组件,详细讲解了Eureka的组成部分,包括服务端和客户端的配置。通过启用`@EnableEurekaServer`和`@EnableEurekaClient`注解,实现服务的注册与发现。文章还提供了启动应用、配置Eureka服务器以及服务发现的实践操作步骤,并展示了如何查看注册服务信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spring cloud eureka

eureka 用以服务发现、服务注册,比较流行的有consul

简介

eureka为netflix开源软件,分为三个部分:

  • eureka服务:用以提供服务注册、发现,已一个war的形式提供 http://search.maven.org/#search%7Cga%7C1%7Ceureka-server
    或者编译源码,将war拷贝进tomcat即可提供服务

  • eureka-server: 相对client端的服务端,为客户端提供服务,通常情况下为一个
    集群

  • eureka-client:客户端,通过向eureka服务发现注册的可用的eureka-server,向后端发送请求

spring cloud eureka

spring cloud eureka 分为两部分

  • @EnableEurekaClient: 该注解表明应用既作为eureka实例又为eureka client 可以发现注册的服务
  • @EnableEurekaServer: 该注解表明应用为eureka服务,有可以联合多个服务作为集群,对外提供服务注册以及发现功能

client

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>springcloud</artifactId>
        <groupId>com.lkl.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eureka</artifactId>

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

        <!--表示为web工程-->
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liaokailin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值