浅谈springcloud常用依赖和配置
作者:放气 发布时间:2023-11-24 07:50:02
标签:springcloud,依赖,配置
spring cloud常用依赖和配置整理
常用依赖
// 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>
<groupId>com.roit</groupId>
<artifactId>config</artifactId>
<version>1.0.0</version>
<!-- 微服务的包 -->
<packaging>pom</packaging>
<!-- spring-boot 父工程 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- spring-cloud 依赖 https://spring.io/projects/spring-cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- 启动类长运行配置 @SpringBootApplication -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- eureka 服务端 @EnableConfigServer http://localhost:8761 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!-- eureka 客户端 @EnableEurekaClient -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<!-- consul 注册 http://localhost:8500/ui/dc1/services -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<!-- nacos 注册 http://localhost:8848/nacos -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<!-- feign 声明式服务调用 替代 RestTemplate @EnableFeignClients -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- hystrix 熔断器,服务降级 @EnableCircuitBreaker -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- hystrix 图形化监控,只能监控一个服务 @EnableHystrixDashboard http://localhost:8769/hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- turbine 聚合监控 @EnableTurbine http://localhost:8769/turbine.stream -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<!-- spring-boot 提供的监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- git 配置类服务端 @EnableConfigServer http://localhost/8888/master/config-dev.yml -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- git 配置类客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- bus-rabbitmq 消息总线,做 config 自动刷新 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<!-- stream-rabbitmq 发送消息 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<!-- sleuth + zipkin 服务链路追踪。需要 zipkin 的 jar包,图形化查看地址 http://localhost:9411 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
</dependencies>
</dependencyManagement>
</project>
配置
// application.yml
# 设置端口
server:
port: 8000
# 服务名
spring:
application:
name: eureka
# eureka 配置
eureka:
instance:
hostname: localhost
client:
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
# 是否需要将自己的路径注册到 eureka 服务端
register-with-eureka: true
# 是否需要从 eureka 服务端抓取路径
fetch-registry: true
# consul
spring:
cloud:
consul:
host: localhost
port: 8500
discovery:
# 注册到 consul 的服务名
service-name: ${spring.application.name}
# 监控界面显示 ip
prefer-ip-address: true
# nacos
spring:
cloud:
nacos:
discovery:
# 服务端地址
server-addr: 127.0.0.1:8848
# ribben 负载均衡策略
provider:
ribbon:
NFloadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
# feign 超时配置, 集成了 ribbon
ribbon:
# 连接超时时间 默认 1000ms
ConnectTimeout: 1000
# 逻辑处理超时时间 默认 1000ms
ReadTimeout: 3000
#feign 集成了 hystrix,开启 hystrix
feign:
hystrix:
enabled: true
# feign 设置日志级别,只支持 debug, 请求响应的相关数据
logging:
level:
com.roit.controller: debug
# turbine 聚合监控
turbine:
combine-host-port: true
# 配置监控的服务名
app-config: provider,consumer
cluster-name-expression: "'default'"
aggregator:
cluster-config: default
#instanceUrlSuffix: /actuator/hystrix.stream
# gateway 网关
spring:
cloud:
gateway:
routes:
- id: provider
# provider 的静态访问路径
# uri: http://localhost:8001/
# 动态
uri: lb://provider
# 匹配规则
predicates:
- Path=/goods/**
# 局部过滤器
filters:
- AddRequestParameter=username,zs
discovery:
locator:
# 请求路径加上微服务名称,http://localhost/provider/goods/ 或 http://localhost/goods/ 都行
enabled: true
# 默认名称大写,改为允许小写
lower-case-service-id: true
# config 服务端
spring:
cloud:
config:
server:
# 文件的仓库地址
git:
uri: https://gitee.com/config.git
# username: zs
# password: 123
# 文件所在分支
label: master
# config 客户端,bootstrap.yml
spring:
cloud:
config:
# http://localhost:8888/master/config-dev.yml
# config 服务端地址
# uri: http://localhost:8888
name: config
profile: dev,redis
label: master
# 动态配置 config 服务端地址,先将config 服务端注册到 eureka
discovery:
enabled: true
# config 服务端的名字,大写
service-id: config-server
# config 客户端 单服务自动刷新
# 1. 加依赖 actuator
# 2. 获取数据的 controller 上加@RefreshScope
# 3. curl -X POST http://localhost:8001/actuator/refresh
management:
endpoints:
web:
exposure:
# * 暴露所有;refresh 暴露自动刷新,/actuator/refresh。
include: '*'
# bus 自动刷新,先给 config-server 发消息,再由 server 去通知所有的 config-client
# bus-amqp 内部使用 rabbitmq 发消息
# config-server 需暴露 bus-refresh 和 配置 rabbitmq
# curl -X POST http://localhost:8888/actuator/bus-refresh
include: 'bus-refresh'
# config-client 需配置 rabbitmq 和 在获取数据的 controller 上加 @RefreshScope
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /
# stream-rabbit
spring:
cloud:
stream:
binders:
# 定义绑定器名称
mybinder:
type: rabbit
# 指定 mq 的环境
environment:
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /
bindings:
# 生产者 @EnableBinding(Source.class)
output:
# 消费者 @EnableBinding(Sink.class), @StreamListener(Sink.INPUT)
# input:
binder: mybinder
# 绑定的交换机名称
destination: myexchange
# sleuth + zipkin
spring:
zipkin:
# zipkin 服务端路径
base-url: http://lacalhost:9411/
sleuth:
sampler:
# 数据采集率 默认0.1
probability: 0.1
来源:https://blog.csdn.net/liu1shi/article/details/117308135


猜你喜欢
- 上移动端的测试课,老师和同学们用的都是eclipse, 只有我一个人用的是idea(用了两款软件之后觉得IDEA更好),真的太难了,配置
- 本文实例为大家分享了Java实现简易俄罗斯方块的具体代码,供大家参考,具体内容如下一、将对象抽象为类首先考虑俄罗斯方块游戏中含有哪些具体的对
- UI设计:实验目的:自主完成一个简单APP的设计工作,综合应用已经学到的Android UI设计技巧,重点注意合理使用布局。实验要求:1.完
- 一、获取企业微信群机器人 Webhook 地址业务需要在企业微信推送告警监控或者定时提醒业务,就可以使用企业微信自带的机器人工具Webhoo
- Mybatis映射文件mapper.xml的注释问题从昨天夜晚9点到今天中午,一直被项目bug所困惑,中间这段时间一直未解决这个问题,也咨询
- 本文实例讲述了C#数据结构之堆栈(Stack)。分享给大家供大家参考,具体如下:堆栈(Stack)最明显的特征就是“先进后出”,本质上讲堆栈
- 开发过程, 我们习惯把数据源配置, 项目常量, 日志配置等基础数据配置写到一个个单独的的文件中. 如jdbc.properties等各种.格
- 汉诺塔游戏一旦掌握了规律,其实是有点单调和无聊的,不过却是学习递归的一个绝佳例子,想当初学习老谭C的时候,就卡在这儿好长时间。对初学编程的人
- 在这篇文章中,我将向您展示如何用新的Java 8 forEach语句循环一个List和Map。1、forEach 和 Map1.1、常规循环
- 一、APP端调用1、注册广播监听查找结果//蓝牙发现设备和查找结束广播IntentFilter intentFilter = new Int
- 本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子
- 本文实例为大家分享了android自定义Camera实现录像和拍照的具体代码,供大家参考,具体内容如下源码:package com.exam
- 1、下载内嵌浏览器Jar包下载地址:点击下载2、项目下加入对应jar;然后右键:Add as Library...3、添加启动项目后事件效果
- 一、前言写今天这篇文章的缘由,其实是来自于前段时间和粉丝的一个聊天,最近他打算参加游戏创作大赛,问我需要准备学习什么知识,以及参加比赛的注意
- 在一些特定的 App 里,我们不希望手机横屏的时候,App 发生旋转,比如微信,企业微信都是这样的。代码可以这样设定:import '
- 本文实例讲述了应用Java泛型和反射导出CSV文件的方法。分享给大家供大家参考。具体如下:项目中有需求要把数据导出为CSV文件,因为不同的类
- 一、简介Spring Cloud Config为分布式系统中的配置提供服务器端和客户端支持。可以集中管理所有环境中应用程序的配置文件。其服务
- mysql实现配置中心本公司配置数据的管理是通过mysql进行配置管理,因为已经搭建好了,所以自己动手重新搭建一遍,熟悉整个流程。有关项目源
- 一、this关键字this是一个引用,它指向自身的这个对象。看内存分析图:假设我们在堆内存new了一个对象,在这个对象里面你想象着他有一个引
- 书上对 i ++ 和 ++ i 的解释如下:int i = 3,a = 0 ;i ++ : 先赋值再运算;例如:a = i ++