SpringCloud入门(十六) ------ Springcloud 集成 consul
程序员文章站
2022-06-12 22:53:33
...
虽然Eureka还可以用,但是官网已经发出了停更公告,所以可以使用其他的注册中心(Zookeeper,Consul等)
安装Consul:
官网下载:
https://www.consul.io/
安装后启动(cmd):
命令行窗口:consul agent -dev
出现running 运行成功
浏览器rul输入: http://localhost:8500/ui/dc1/services
SpringCloud 集成 consul 实现服务注册:
pom:
<!-- consul -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
完整的依赖:
<dependencies>
<dependency>
<groupId>com.jym.springCloud</groupId>
<artifactId>jym-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId></dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- consul -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
</dependencies>
yml:
server:
port: 8005
spring:
application:
name: jym-provider-payment # 微服务名称
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${spring.application.name}
启动类:
package com.jym.springCloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @program: jym-springcloud-parent
* @description: 启动类
* @author: jym
* @create: 2020/03/13
*/
@SpringBootApplication
@EnableDiscoveryClient
public class JymPaymentApplication8005 {
public static void main(String[] args) {
SpringApplication.run(JymPaymentApplication8005.class,args);
}
}
启动之后查看consul界面:
调用端与服务端的步骤一致
学习年限不足,知识过浅,说的不对请见谅。
世界上有10种人,一种是懂二进制的,一种是不懂二进制的。
下一篇: 心肌梗塞饮食有什么禁忌吗
推荐阅读
-
springcloud学习之路: (五) springcloud集成SpringCloudConfig分布式配置中心
-
springcloud学习之路: (四) springcloud集成Hystrix服务保护
-
springcloud Springboot vue.js Activiti6 前后分离 跨域 工作流 集成代码生成器 shiro权限
-
带你入门SpringCloud 之 通过SpringCloud Bus 自动更新配置
-
SpringCloud Zuul基于Consul配置及详解
-
SpringCloud入门hello world,SpringBoot2.1.3,附采坑经历
-
Kubernetes SpringCloud持续集成 - 安装jenkins、配置模板pod(一)
-
springcloud vue 微服务分布式 activiti工作流 前后分离 集成代码生成器 shiro权限
-
转:SpringCloud服务注册中心比较:Consul vs Zookeeper vs Etcd vs Eureka
-
SpringCloud入门学习笔记2--eureka