博客
关于我
SpingCloud 2020微服务教程【17】服务提供者注册进Consul
阅读量:78 次
发布时间:2019-02-26

本文共 2617 字,大约阅读时间需要 8 分钟。

视频链接:

文章源码:

cloud-providerconsul-payment8006模块

微服务模块

1. 建module

New --> Module --> Maven[Module SDK:1.8.0_191] --> name[cloud-providerconsul-payment8006] --> Finish

2. 改pom

cloud2020
com.antherd.springcloud
1.0-SNAPSHOT
4.0.0
cloud-providerconsul-payment8006
org.springframework.cloud
spring-cloud-starter-consul-discovery
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-devtools
runtime
true
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test

3. 写yml

server:  port: 8006spring:  application:    name: consul-provider-payment  cloud:    consul:      host: localhost      port: 8500      discovery:        #hostname: 127.0.0.1        service-name: ${   spring.application.name}

4. 主启动

新建类:com.antherd.springcloud.PaymentMain8006

package com.antherd.springcloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication@EnableDiscoveryClientpublic class PaymentMain8006 {     public static void main(String[] args) {       SpringApplication.run(PaymentMain8006.class, args);  }}

新建类:com.antherd.springcloud.controller.PaymentController

package com.antherd.springcloud.controller;import java.util.UUID;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Value;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@Slf4jpublic class PaymentController {     @Value("${server.port}")  private String serverPort;  @RequestMapping(value = "/payment/consul")  public String paymentConsul() {       return "Spring Cloud with Consul: " + serverPort + "\t" + UUID.randomUUID().toString();  }}

5. 启动测试

登录Consul服务器,查看节点,发现consul-provider-payment已经被注册到consul

consul-provider-payment已经被注册到consul
访问接口看一下是否能正常调用吧

转载地址:http://yjtz.baihongyu.com/

你可能感兴趣的文章
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>
MySQL中的关键字深入比较:UNION vs UNION ALL
查看>>
mysql中的四大运算符种类汇总20多项,用了三天三夜来整理的,还不赶快收藏
查看>>
mysql中的字段如何选择合适的数据类型呢?
查看>>
MySQL中的字符集陷阱:为何避免使用UTF-8
查看>>
mysql中的数据导入与导出
查看>>
MySQL中的时间函数
查看>>
mysql中的约束
查看>>
MySQL中的表是什么?
查看>>
mysql中穿件函数时候delimiter的用法
查看>>
Mysql中索引的分类、增删改查与存储引擎对应关系
查看>>
Mysql中索引的最左前缀原则图文剖析(全)
查看>>
MySql中给视图添加注释怎么添加_默认不支持_可以这样取巧---MySql工作笔记002
查看>>
Mysql中获取所有表名以及表名带时间字符串使用BetweenAnd筛选区间范围
查看>>
Mysql中视图的使用以及常见运算符的使用示例和优先级
查看>>
Mysql中触发器的使用示例
查看>>
Mysql中设置只允许指定ip能连接访问(可视化工具的方式)
查看>>
mysql中还有窗口函数?这是什么东西?
查看>>
mysql中间件
查看>>