当前位置: 首页 > news >正文

SpringCloud-Config

一、介绍

(1)服务注册中心
(2)管理各个服务上的application.yml,支持动态修改,但不会影响客户端配置
(3)一般将application.yml文件放在git上,客户端通过http/https方式拉取

二、项目搭建

(1)建个远程仓库,创建两个配置文件application.yml
在这里插入图片描述
(2)编写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>demo20220821</artifactId><groupId>com.wsh.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-config-config3344</artifactId><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>com.wsh.springcloud</groupId><artifactId>cloud-api-common</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.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
</project>

(3)编写application.yml文件

server:port: 3344spring:application:name: cloud-config-servicecloud:config:server:git:uri: https://gitee.com/xxx/config.gitlabel: mastereureka:client:#    客户端设置为trueregister-with-eureka: true#    客户端设置为truefetch-registry: trueservice-url:#      defaultZone: http://localhost:7001/eurekadefaultZone: http://eureka1.com:7001/eureka, http://eureka2.com:7002/eurekainstance:instance-id: config3344prefer-ip-address: true

(4)编写启动类

package com.wsh.springcloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;/*** @ClassName ConfigMain3344* @Description: TODO* @Author wshaha* @Date 2023/10/15* @Version V1.0**/
@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class ConfigMain3344 {public static void main(String[] args) {SpringApplication.run(ConfigMain3344.class, args);}
}

(5)运行
在这里插入图片描述

三、客户端读取

(1)application.yml是用户级的,bootstrap.yml是系统级的,优先级更高
(2)编写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>demo20220821</artifactId><groupId>com.wsh.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-config-client3355</artifactId><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>com.wsh.springcloud</groupId><artifactId>cloud-api-common</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.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
</project>

(3)编写bootstrap.yml

server:port: 3355spring:application:name: cloud-config-client-servicecloud:config:label: master #分支名name: application # - 号前缀profile: prod # - 号后缀uri: http://localhost:3344 #配置中心地址eureka:client:#    客户端设置为trueregister-with-eureka: true#    客户端设置为truefetch-registry: trueservice-url:#      defaultZone: http://localhost:7001/eurekadefaultZone: http://eureka1.com:7001/eureka, http://eureka2.com:7002/eurekainstance:instance-id: configClient3355prefer-ip-address: true

(4)编写启动类

package com.wsh.springcloud;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;/*** @ClassName ConfigMain3344* @Description: TODO* @Author wshaha* @Date 2023/10/15* @Version V1.0**/
@SpringBootApplication
@EnableEurekaClient
public class ConfigClientMain3355{public static void main(String[] args) {SpringApplication.run(ConfigClientMain3355.class, args);}
}

(5)编写Controller

package com.wsh.springcloud.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;/*** @ClassName ConfigClientController* @Description: TODO* @Author wshaha* @Date 2023/10/15* @Version V1.0**/
@RestController
public class ConfigClientController {@Value("${teset.name}")private String name;@RequestMapping("/getConfig")public String getConfig(){return name;}
}

(6)运行
在这里插入图片描述

四、手动刷新客户端配置

(1)暴露actuator

server:port: 3355spring:application:name: cloud-config-client-servicecloud:config:label: master #分支名name: application # - 号前缀profile: prod # - 号后缀uri: http://localhost:3344 #配置中心地址eureka:client:#    客户端设置为trueregister-with-eureka: true#    客户端设置为truefetch-registry: trueservice-url:#      defaultZone: http://localhost:7001/eurekadefaultZone: http://eureka1.com:7001/eureka, http://eureka2.com:7002/eurekainstance:instance-id: configClient3355prefer-ip-address: truemanagement:endpoints:web:exposure:include: "*"

(2)Controller增加注解@RefreshScope

package com.wsh.springcloud.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @ClassName ConfigClientController* @Description: TODO* @Author wshaha* @Date 2023/10/15* @Version V1.0**/
@RestController
@RefreshScope
public class ConfigClientController {@Value("${teset.name}")private String name;@RequestMapping("/getConfig")public String getConfig(){return name;}
}

(3)执行命令,必须是POST请求

curl -X POST "http://localhost:3355/actuator/refresh"

相关文章:

SpringCloud-Config

一、介绍 &#xff08;1&#xff09;服务注册中心 &#xff08;2&#xff09;管理各个服务上的application.yml&#xff0c;支持动态修改&#xff0c;但不会影响客户端配置 &#xff08;3&#xff09;一般将application.yml文件放在git上&#xff0c;客户端通过http/https方式…...

劣币驱良币的 pacing 之殇

都说 pacing 好 burst 孬(参见&#xff1a;为啥 pacing)&#xff0c;就像都知道金币好&#xff0c;掺铁金币孬一样。可现实中掺铁的金币流通性却更好&#xff0c;劣币驱良币。劣币流通性好在卖方希望收到别人的良币而储存&#xff0c;而自己作为买方只使用劣币。 burst 和 pac…...

Gin 中的 Session(会话控制)

Session 介绍 session和cookie实现的底层目标是一致的,但是从根本而言实现的方法是不同的; session 是另一种记录客户状态的机制, 不同的是 Cookie 保存在客户端浏览器中,而 session保存 在服务器上 ; Session 的工作流程 当客户端浏览器第一次访问服务器并发送请求时,服…...

ChatGPT AIGC 实现数据分析可视化三维空间展示效果

使用三维空间图展示数据有以下一些好处&#xff1a; 1可视化复杂性&#xff1a;三维图可以展示三个或更多的变量&#xff0c;一眼就能看出数据各维度之间的关系&#xff0c;使复杂数据的理解和分析变得更为直观。 2检测模式和趋势&#xff1a;通过三维图&#xff0c;用户可以…...

Stable Diffusion 动画animatediff-cli-prompt-travel

基于 sd-webui-animatediff 生成动画或者动态图的基础功能,animatediff-cli-prompt-travel突破了部分限制,能让视频生成的时间更长,并且能加入controlnet和提示词信息控制每个片段,并不像之前 sd-webui-animatediff 的一套关键词控制全部画面。 动图太大传不上来,凑合看每…...

fatal error C1083: 无法打开包括文件: “ta_libc.h”: No such file or directory

用python做交易数据分析时&#xff0c;可以用talib库计算各类指标&#xff0c;这个库通过以下命令安装&#xff1a; pip install TA-Lib -i https://pypi.tuna.tsinghua.edu.cn/simple windows安装时可能出现本文标题所示的错误&#xff0c;可按如下步骤解决&#xff1a; 1、去…...

c 语言基础题目:L1-034 点赞

微博上有个“点赞”功能&#xff0c;你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签&#xff0c;而你点赞的博文的类型&#xff0c;也间接刻画了你的特性。本题就要求你写个程序&#xff0c;通过统计一个人点赞的纪录&#xff0c;分析这个人的特性。 …...

SaaS人力资源管理系统的Bug

SaaS人力资源管理系统的Bug Bug1【18】 这里我是直接把代码复制过来的&#xff0c;然后就有一个空白 这是因为它的代码有问题&#xff0c;原本的代码如下所示 <el-table-column fixed type"index" label"序号" width"50"></el-table…...

GPTQ 和 AWQ:LLM 量化方法的比较

大语言模型&#xff08;LLM&#xff09;在自然语言处理&#xff08;NLP&#xff09;任务中取得了显著的进展。然而&#xff0c;LLM 通常具有非常大的模型大小和计算复杂度&#xff0c;这限制了它们在实际应用中的部署。 量化是将浮点数权重转换为低精度整数的过程&#xff0c;…...

JVM:虚拟机类加载机制

JVM:虚拟机类加载机制 什么是JVM的类加载 众所周知&#xff0c;Java是面向对象编程的一门语言&#xff0c;每一个对象都是一个类的实例。所谓类加载&#xff0c;就是JVM虚拟机把描述类的数据从class文件加载到内存&#xff0c;并对数据进行校验&#xff0c;转换解析和初始化&a…...

PHP筆記

​ 前言因緣際會下還是開始學習php了。經歷了風風雨雨終於在今年暑假要去加拿大留學了&#xff0c;php會是第二年的其中一門必修課程&#xff0c;加上最近前端也真的蠻心累&#xff0c;也許有一門精進的後端語言&#xff0c;日後轉職會有更寬廣的道路&#xff0c;對自己說加油&…...

IDEA启动报错Failed to create JVM. JVM path的解决办法

今天启动IDEA时IDEA报错&#xff0c;提示如下。 if you already hava a JDK installed, define a JAVA_HOME variable in Computer > Systen Properties > System Settings > Environment Variables.Failed to create JVM. JVM path:D:\ideaIU2023.2.3\IntelliJ IDE…...

源码解析FlinkKafkaConsumer支持周期性水位线发送

背景 当flink消费kafka的消息时&#xff0c;我们经常会用到FlinkKafkaConsumer进行水位线的发送&#xff0c;本文就从源码看下FlinkKafkaConsumer.assignTimestampsAndWatermarks指定周期性水位线发送的流程 FlinkKafkaConsumer水位线发送 1.首先从Fetcher类开始&#xff0c…...

Nginx:动静分离(示意图+配置讲解)

示意图&#xff1a; 动静分离 动静分离是指将动态内容和静态内容分开处理的一种方式。通常&#xff0c;动态内容是指由服务器端处理的&#xff0c;例如动态生成的网页、数据库查询等。静态内容是指不需要经过服务器端处理的&#xff0c;例如图片、CSS、JavaScript文件等。通过…...

通讯网关软件024——利用CommGate X2Access实现Modbus TCP数据转储Access

本文介绍利用CommGate X2ACCESS实现从Modbus TCP设备读取数据并转储至ACCESS数据库。CommGate X2ACCESS是宁波科安网信开发的网关软件&#xff0c;软件可以登录到网信智汇(http://wangxinzhihui.com)下载。 【案例】如下图所示&#xff0c;实现从Modbus TCP设备读取数据并转储…...

vim工具的使用

目录 vi/vim键盘图 1、vim的基本概念 2、vim的基本使用 3、vim命令模式命令集 4、vim底行模式命令集 5、参考资料 vi/vim键盘图 1、vim的基本概念 vi和vim的区别&#xff1a;vi和vim的区别简单点来说&#xff0c;它们都是多模式编辑器&#xff0c;不同的是vim是vi…...

Docker学习_存储篇

当以默认的方式创建容器时&#xff0c;容器中的数据无法直接和其他容器或宿主机共享。为了解决这个问题需要学习一些Docker 存储卷的知识。 Docker提供了三种存储的方式。 bind mount共享宿主机文件目录volume共享docker存储卷tmpfs mount共享内存 volume* volume方式是容器…...

微信小程序获取当前日期时间

一、直接使用方式 在小程序中获取当前系统日期和时间&#xff0c;可直接拿来使用的常用的日期格式 //1. 当前日期 YYYY-MM-DDnew Date().toISOString().substring(0, 10)new Date().toJSON().substring(0, 10)//2. 当前日期 YYYY/MM/DDnew Date().toLocaleDateString()//3.…...

Unity关键词语音识别

一、背景 最近使用unity开发语音交互内容的时候&#xff0c;遇到了这样的需求&#xff0c;就是需要使用语音关键字来唤醒应用程序&#xff0c;然后再和程序做交互&#xff0c;有点像智能音箱的意思。具体的技术方案方面&#xff0c;也找了一些第三方的服务&#xff0c;比如百度…...

SpringBoot的配置文件——.yml和.properties

目录 1. Spring Boot 配置文件的使用场景 2. 配置文件的两种格式 2.0 特殊说明&#xff1a; 2.1 .properties 2.1.1 格式 2.2.2 缺陷 2.2.3 解决中文乱码的问题 2.2 .yml 2.2.3 格式 配置数据库连接 注意转义字符 ​编辑 ​编辑 配置null 配置对象 从.yml读取文件举例 Stud…...

手机网站建设:新手指南,一步到位打造完美移动版网站 关键词: 手机网站建设, 移动网站设计, 响应式设计, SEO优化, 用户体验

...

VibeVoice API接口调用案例:WebSocket流式通信实测

VibeVoice API接口调用案例&#xff1a;WebSocket流式通信实测 1. 项目概述 VibeVoice 是一个基于微软开源模型的实时语音合成系统&#xff0c;能够将文本内容快速转换为高质量的语音输出。这个系统特别适合需要实时语音交互的应用场景&#xff0c;比如语音助手、有声读物制作…...

QT6 + CMake + QML开发:你的图片和QML文件加载不出来?可能是.qrc没配对

QT6 CMake QML开发&#xff1a;资源加载失败的终极排查指南 当你花了几个小时精心设计了QML界面&#xff0c;却在运行时看到一片空白或"找不到文件"的错误提示时&#xff0c;那种挫败感每个QT开发者都深有体会。特别是在QT6和CMake的现代开发环境中&#xff0c;资源…...

面试复盘(Debrief)的艺术:挂了面试不可怕,如何通过感谢信获取真实Feedback并为下次“埋伏笔”?

在2026年竞争极其激烈的北美科技求职市场中&#xff0c;即使是背景最优秀的候选人&#xff0c;也必然会经历面试失败。在工业界的招聘漏斗中&#xff0c;由于技术栈匹配度、团队预算&#xff08;Headcount&#xff09;变动或单纯的竞争者过强&#xff0c;收到拒信&#xff08;R…...

用随机森林预测空气质量?先看看这6个特征谁说了算!(Python特征重要性分析与可视化实战)

随机森林特征重要性分析&#xff1a;解码空气质量预测的6大关键因素 当数据科学家们谈论空气质量预测时&#xff0c;常常陷入一个误区——过分关注模型的预测准确率&#xff0c;却忽视了模型背后的故事。想象一下&#xff0c;你花费数周时间调优的随机森林模型预测准确率达到了…...

保姆级教程:手把手教你下载SEED-VIG脑电数据集(附Gitee国内镜像地址)

从零到一&#xff1a;SEED-VIG脑电数据集的完整获取与解析指南 第一次接触SEED-VIG数据集时&#xff0c;我花了整整三天时间才搞明白如何正确下载和解析这个2.9GB的庞然大物。作为研究驾驶疲劳检测的重要资源&#xff0c;这个数据集的价值毋庸置疑&#xff0c;但获取过程却让不…...

如何快速上手Jable视频下载工具:新手必备的完整指南

如何快速上手Jable视频下载工具&#xff1a;新手必备的完整指南 【免费下载链接】jable-download 方便下载jable的小工具 项目地址: https://gitcode.com/gh_mirrors/ja/jable-download 还在为无法保存Jable上的精彩视频而烦恼吗&#xff1f;今天我要为你介绍一款简单实…...

【Mojo+Python企业级混合编程实战指南】:20年架构师亲授3大高频场景落地方法论

第一章&#xff1a;Mojo与Python混合编程的企业级价值全景图Mojo 是一种专为 AI 原生系统设计的现代系统编程语言&#xff0c;兼具 Python 的表达力与 C/Rust 级别的性能。在企业级 AI 工程实践中&#xff0c;Mojo 并非旨在替代 Python&#xff0c;而是以“无缝互操作”为核心理…...

技术难题攻克指南:Retrieval-based-Voice-Conversion-WebUI常见问题全景解析

技术难题攻克指南&#xff1a;Retrieval-based-Voice-Conversion-WebUI常见问题全景解析 【免费下载链接】Retrieval-based-Voice-Conversion-WebUI Easily train a good VC model with voice data < 10 mins! 项目地址: https://gitcode.com/GitHub_Trending/re/Retrieva…...

3步解决ComfyUI-Florence2视觉语言模型加载失败:实战配置指南

3步解决ComfyUI-Florence2视觉语言模型加载失败&#xff1a;实战配置指南 【免费下载链接】ComfyUI-Florence2 Inference Microsoft Florence2 VLM 项目地址: https://gitcode.com/gh_mirrors/co/ComfyUI-Florence2 当您在ComfyUI中部署Microsoft Florence2视觉语言模型…...