springcloud 配置中心

SpringCloud之Config配置中心 目录`config` 简介`config` 作用`config` 架构 config 简介 springcloud config 项目是一个解决分布式系统的配置管理方案。它包含了 client 和 server 两个部分,server 端提供配置文件的存储、以接口的形式将配置文件的内容提供出去,client 端通过接口获取数据、并依据此数据初始化自己的应用 目前 springcloud config 的使用主要是通过 git/svn 方式做一个配置中心,然后每个服务从其中获取自身配置所需的参数 spring 阅读详情

1.config pom文件

<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.knife</groupId>
	<artifactId>ConfigTest</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>ConfigTest</name>
	<url>http://maven.apache.org</url>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.5.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>
		<spring-cloud.version>Finchley.SR1</spring-cloud.version>
	</properties>

	<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>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>


	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
</project>

2.配置文件

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:10000/eureka/
spring:
  application:
    name: springcloud-config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/wangzhejun/springcloudconfig.git
          search-paths: /springcloudconfig
          username: *******
          password: *******
server:
  port: 9005

3.启动类

package com.knife.ConfigTest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;

@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
public class ConfigApp 
{
    public static void main( String[] args )
    {
    	SpringApplication.run(ConfigApp.class,args);
    }
}

4.启动配置项目,访问浏览器能看到git 上的配置信息

{"name":"application","profiles":["dev"],"label":"master","version":"3893e4e9589514a16f3ae2b22469c59c37a42d08","state":null,"propertySources":[{"name":"https://gitee.com/wangzhejun/springcloudconfig.git/application-dev.yml","source":{"my.message":1234567,"word":"test"}}]}

5.客户端pom文件

<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.knife</groupId>
  <artifactId>ProviderTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>ProviderTest</name>
  <url>http://maven.apache.org</url>

  <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.5.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>
		<spring-cloud.version>Finchley.SR1</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
		</dependency>
		
		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
		
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
</project>

 6.客户端配置bootstrap.yml(优先级高于application.yml)

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:10000/eureka/
spring: 
  application: 
    name: providerTest
  cloud:
    config:
      name: application
      profile: dev
      label: master
      discovery:
        enabled: true
        serviceId: springcloud-config
server:
  port: 2222

7.启动类

package com.knife.ProviderTest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;


@EnableDiscoveryClient
@SpringBootApplication
public class ProviderApp {

	public static void main(String[] args) {
		SpringApplication.run(ProviderApp.class, args);
	}
}

8.controller层

package com.knife.ProviderTest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProviderController {
	
	@Value("${my.message}")
	private String message;

	@RequestMapping(value = "/test", method = RequestMethod.GET)
	public String test() {
		return "i am provider "+message;
	}

}

9.启动客户端能看到获取配置日志

2019-12-02 13:38:37.088  INFO 9720 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://172.17.10.30:9005/
2019-12-02 13:38:39.725  INFO 9720 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=application, profiles=[dev], label=master, version=a89ea039203db1937ad0f7b726ba558e3b9a8a74, state=null
2019-12-02 13:38:39.726  INFO 9720 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://gitee.com/wangzhejun/springcloudconfig.git/application-dev.yml'}]}

 

springcloud入门之配置中心 开发分布式系统如果还是各个服务配置文件单独配置肯定是不行的,springcloud使用的解决方案是搭建配置中心将并指定一个配置文件路径如git项目对配置文件进行统一管理。 在Spring Cloud中,提供了分布式配置中心组件spring cloud config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在实现cloud config中,主要有两个角色:作为配置 阅读详情

相关推荐

SpringCloud系列之分布式配置中心急速入门教程

分布式微服务项目,就会有很多的模块,比如微服务A、微服务B等等,每个工程都有一套配置文件,随着业务增长,肯定会有很多配置,分散管理,不能实现统一的管理,所以就有了微服务的配置文件统一管理组件,比如spring cloud官方的spring cloud config、携程的 Apollo,还有最近比较火的阿里 nacos,每款产品各有自己的特点,不过本博客只介绍spring cloud config

Nicky's blog 4536

Spring Cloud 学习(27) --- Spring Cloud Config(二) 刷新配置

刷新配置信息的方式有三种:手动刷新、半自动刷新、自动刷新,其中,半自动刷新利用的是 spring cloud bus,自动刷新利用的是 github、gitee、gitlab 等代码托管网站的 webhooks 手动刷新 源码:https://gitee.com/laiyy0728/spring-cloud/tree/master/spring-cloud-config/spring-clou...

霓虹深处 800

OCEAN 电路仿真

介绍利用 Cadence OCEAN 进行电路脚本仿真的方法

weixin_43249158的博客 4402

Spring Cloud 配置中心 Spring Cloud Config 入门

1. 概述 Spring Cloud Config是由 Spring Cloud 官方推出,基于 Spring Cloud 体系的配置中心。 相比Nacos、Apollo等其它配置中心来说,Spring Cloud Config 是一个轻量级的配置中心,和 Spring Cloud 的集成度会更好,不过功能上会薄弱一些。例如说,灰度发布、运维界面、配置回滚等等。因此,还是推荐使用 Apollo 或者 Nacos 嘿嘿~ Spring Cloud Config 整体架构如下图所示: 一共分成 S...

weixin_42073629的博客 1173

Jetson Nano摄像头选型与配置全攻略:CSI与USB接口实战指南

在嵌入式视觉与边缘计算项目中,摄像头作为核心传感器,其选型与配置直接影响系统性能。CSI(Camera Serial Interface)和USB(Universal Serial Bus)是两种主流接口,前者通过MIPI CSI-2协议直接与SoC通信,具备低延迟、高带宽特性,适合实时性要求高的应用;后者基于通用串行总线标准,即插即用,通用性强。在NVIDIA Jetson Nano平台上,合理选择摄像头接口并优化驱动配置,能充分发挥其GPU加速优势,提升图像处理流水线效率。本文聚焦Jetson Nano

weixin_29190651的博客 323

企业数字化转型解决方案架构设计:一个五维全景视角

本文系统探讨了企业数字化转型的架构设计框架,提出五维协同模型:企业架构作为战略罗盘,业务架构聚焦价值创造,应用架构实现能力载体,数据架构提供智能燃料,技术架构奠定基础支撑。文章深入分析了各架构域的核心要素、设计原则及相互关系,并指出数字化转型需通过渐进路径,结合战略引领、技术赋能和组织变革,构建有机统一的架构体系。该框架为企业应对数字化复杂性提供了系统性方法论,强调从整体视角实现技术与业务的深度融合。

金牌架构师 1256

springcloud本地服务拉取云服务器配置中心配置文件失败

最近练手一个springcloud的项目,将eureka和configserver部署在云服务器上,本地开发业务,出现拉取配置文件失败报错 报错忘记截图了,已经解决不想再改回去了,正常情况下拉取配置文件是这样的: Fetching config from server at:http://ip:端口 Located environment:...... 如果连接失败,会出现连接超时 出现问题原因...

qq_36829588的博客 1997

Central Finance 全景解析:用 SAP S/4HANA 构建跨系统的财务中台与渐进式转型路径

Central Finance 是基于 SAP S/4HANA 的一种部署与应用场景:在不打断现有异构源系统运营的前提下,把多套 SAP 与非 SAP 系统中的财务与管理会计数据实时/准实时复制到一套中心化的 SAP S/4HANA 中,作为统一的记账与分析底座,逐步把选定的财务流程(如预算控制、付款、固定资产结账等)迁入中心系统。这让企业既能快速获得统一报表与统一核算结构,又为未来的整体迁移留出了弹性路径。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 390

Spring Cloud 学习(29) --- Spring Cloud Config(四) Spring Cloud 配置、高可用

本地参数覆盖远程参数 spring: cloud: config: allow-override: true override-none: true override-system-properties: false allow-override:标识 override-system-properties 是否启用,默认为 true,设置为 ...

霓虹深处 1625

EtherCAT主站教程3--适配伺服驱动器(模式配置)

目前通用的伺服驱动器的位置模式、速度模式以及其他模式是伺服系统中常见的控制模式,切换这些模式通常需要根据具体的伺服驱动器型号和控制协议(如EtherCAT、CANopen、Modbus等)进行配置。以下是这些模式的概述及切换方法的一般性指导:协议规范中,一共有以下几种模式:其中模式1、3、6对于比较常用,也更容易上手。

weixin_52626887的博客 793

基于pytorch cnn ResNets卷积网络的模糊图像检测 完整代码数据直接运行

基于pytorch cnn ResNets卷积网络的模糊图像检测 完整代码数据直接运行

730

spring cloud 配置中心启动分析

spring cloud 配置中心是一个管理应用配置的工具组件 用到了gitlab 保存配置文件 配置中心本身是一个spring boot 服务 在对应目录中 配置 好 gitlab 上保存配置的地址 使用服务名/profire/版本 来获取 配置 例如 : 启动命令: --spring.profile.level=DEBUG --eureka.client.register-with-eure...

keep_learn的专栏 511

RK平台内核“大瘦身”:从4GB到500MB的蜕变之旅

摘要:本文详细介绍了RK平台内核裁剪的完整流程与技术要点。通过对RK3568/RK3588等SoC平台的分析,探讨了从初始4GB内核精简至500MB的具体方法。文章系统阐述了前期硬件环境搭建、软件工具准备、SDK源码获取等准备工作,深入解析了内核模块组成及可裁剪部分,并提供了图形化配置界面的详细操作指南。同时,对编译烧录过程和常见问题解决方案进行了说明,强调了备份和谨慎选择裁剪项的重要性。最后展望了内核裁剪技术在物联网和边缘计算等领域的应用前景,为开发者提供了实用的内核优化参考方案。(148字)

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 443

【spring cloud】(五)配置中心——springcloud Config

简单来说,Spring Cloud Config就是我们通常意义上的配置中心,也就是微服务项目中,每一个微服务都需要配置相应的配置,如果不同服务的配置文件有相同的配置,如果这些相同配置需要修改的话就可以在配置中心上进行修改。

扎哇太枣糕的笔记博客 1773

【NI Multisim 14.0原理图设计基础——元器件分类】

电阻(RESISTOR):该元器件栏中的电阻都是标称电阻,是根据真实电阻元器件而设计的,其电阻值不能改变。 排阻(RESISTOR PACK):相当于多个电阻并列封装在一个壳内,它们具有相同的阻值。 电位器(POTENTIOMETER):即可调电阻,可以通过键盘字母动态调节电阻,大写表示增加电阻值,小写表示减小电阻值,调节增量可以设置。 电容(CAPACITOR):所有电容都是无极性的,不能改变参数,没有考虑误差,也未考虑耐压大小。 电解电容器(CAP_ELECTROLIT):所有电容都是有极性的,“+”极

RL2698853114的博客 4万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

[SpringCloud] SpringCloud配置中心的核心原理

SpringCloud中配置中心的核心原理

959 1326

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

SpringCloud之配置中心

一、springCloud核心组件config 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大 量的服务。 由于每个服务都需要必要的配置信息才能运行,所以一套集中式的,动态的配置管理设施是必不可少的。 Spring Cloud 提供了 ConfigServer来解决这个问题. Spring Cloud Config 为微服务架构中的微服务提供集中化的外部配置支持,配置服务器为各个不同微服 务应用的所有环境提供了一个中心化的外部配置。...

m0_53151031的博客 5801

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【微服务架构】SpringCloud(七):配置中心 Spring Cloud Config

存放配置的地方:git ,本地文件 等。从 1 读取配置。是 config server 的客户端 消费配置。

专注上位机开发、机器视觉、机器学习、嵌入式软硬件开发 1万+

SpringCloud配置中心

一、SpringCloud Config 微服务意味着要将单体应用中的业务拆分成一个个子服务 , 每个服务的粒度相对较小 , 因此系统中会出现大量的服务。 由于每个服务都需要必要的配置信息才能运行 , 所以一套集中式的 , 动态的配置管理设施是必不可少的。 Spring Cloud 提供了 ConfigServer 来解决这个问题 . Spring Cloud Config 为微服务架构中的微服务提供集中化的外部配置支持 , 配置服务器为各个不同微服务应用的所有环境提供了一个中心化的外部配置。 Sp

m0_60375943的博客 584

SpringCloud:Spring Cloud Config Github配置中心

随着分布式项目越来越大,勤劳的程序猿们会开始面临一个挑战,配置文件会越来越繁杂,虽然spring提供了一个鸡肋版的解决方案,spring.profiles.active,在大型的分布式项目体系中,聊胜于无吧,手动维护配置文件的痛苦,生产,UAT,测试,开发环境的隔离,额外的配置文件,如:logback.xml日志的配置文件,bootstrap.properties配置文件,当系统中有几十个服务,相应的会有上百个配置文件,简直就是史诗级的灾难大片,每次发布上线,都要手动去检查配置文件,相应的服务都需要重启,那

m0_46413263的博客 278

Zookeeper作为SpringCloud配置中心

一、背景介绍 在分布式系统中动态配置中,可以避免重复重启服务,动态更改服务参数等。一句话非常重要。 哈哈。 Zookeeper 作为知名的分布式调度系统, 我们也可以利用其作为配置中心,其wacther 主动通知机制, 可以将node 节点数据变更信息及时通知到client 端。 环境依赖 名称 值 备注 JDK 1.8 Consul 1.5.2 注册中心,Consul安装及...

希望我的博客,能解决你工作中的问题 7412

springcloud-config配置中心

微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务。由于每个服务都需要必要的配置信息才能运行,所以一套集中式的、动态的配置管理设施是必不可少的(配置指的是springboot项目当中的application.properties/application.yml)

怪咖@的博客 3268

Spring Cloud-SpringCloud概述&注册中心和配置中心Nacos

spring没有重复造轮子,只是基于springboot讲其他公司(Netflix)的框架组合起来springcloud是一套微服务开发的全家桶Nacos(na代表naming,co代表configuration,s是service)是阿里巴巴一个开源的注册中心、配置中心组件。

qq_63743896的博客 1355
上一篇: springcloud zuul
下一篇: springcloud hystrix
knife1220
博客等级 码龄15年 33粉丝 176原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值