springcloud,consul作为注册服务中心的使用

本文介绍了如何下载并启动Consul,通过官方链接或百度网盘。然后展示了在Spring Cloud项目中配置和使用Consul进行服务发现的过程,包括添加依赖、配置yml文件,并启动服务进行注册验证。提供了详细的pom.xml配置和yml配置示例。
摘要由CSDN通过智能技术生成

一、下载地址

官网
https://www.consul.io/downloads.html
或者我的网盘,服务到位吧
链接:https://pan.baidu.com/s/1G3J4-N1I8tkk9Bxcyj_Vpw 
提取码:cid4 
复制这段内容后打开百度网盘手机App,操作更方便哦
启动consul,在consul目录下面cmd
consul agent -dev 
http://localhost:8500/ui/dc1/services 查看这个界面我还是蛮喜欢的,哈哈哈

在这里插入图片描述
然后呢,跟之前一样,在父工程中新建module,导入pom,创建yml,创建启动类四部曲

pom来也

        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
 

yml如下

server:
  port: 8006


spring:
  application:
    name: consul-provider-payment
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        service-name: ${spring.application.name}
 
 

启动测试就好了,查看是否注册进consul

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

@我不是大鹏

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

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

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

打赏作者

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

抵扣说明:

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

余额充值