SrpingCloud 之SrpingCloud config分布式配置中心搭建
1、搭建git环境 目的:持久化存储配置文件信息
采用码云
创建后
继续创建文件夹 用来区分不同的项目
下面就是git上存放配置文件了。环境的区分 dev sit pre prd 开发 测试 预发布 准生产
sit 和 prd 环境
ConfigServer环境搭建:
注意Config server也需要注册到注册中心的 client通过别名去读取 而不是实际地址哦
分别去对应:
###服务注册到eureka地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka
spring:
application:
####注册中心应用名称
name: config-server
cloud:
config:
server:
git:
###git环境地址
uri: https://gitee.com/toov5/distributed_configuration_file.git
####目录文件(区分项目的)
search-paths:
- Test
####读取分支环境
label: master
####服务端口号
server:
port: 8888
启动类:
package com.toov5; 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; @SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class AppConfigServer {
public static void main(String[] args) {
SpringApplication.run(AppConfigServer.class, args);
}
}
开启Eureka 开启 ConfigServer
下面验证配置文件:
把配置文件存放在git
在git环境上创建配置文件命名规范
服务名称-配置名称-环境
提交以后,启动项目,访问:
下面就是 搭建client 去使用配置文件
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.toov5</groupId>
<artifactId>SpringCloud-Configclient</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<!-- 管理依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</version>
<type>pom</type>
<scope>import</scope>
</dependency> </dependencies>
</dependencyManagement>
<dependencies>
<!-- SpringBoot整合Web组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<!-- SpringBoot整合eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> </project>
bootstrap.yml (注意一定要utf-8格式的!)
spring:
application:
####注册中心应用名称 git上的前缀
name: test-configClient
cloud:
config:
####读取后缀 prd是对应的后缀
profile: prd
####读取config-server注册地址 confit-server的注册名称 别名
discovery:
service-id: config-server
enabled: true
##### eureka服务注册地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka
server:
port: 8882
controller
package com.toov5.controller; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class TestController {
@Value("${motto}") //配置的key
private String motto; @RequestMapping("/getMotto")
public String getMotto() {
return motto;
}
}
启动
package com.toov5.controller; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class AppConfigClient {
public static void main(String[] args) {
SpringApplication.run(AppConfigClient.class, args);
}
}
bootstrap.yml文件一定要 utf-8格式的! LZ在写次博文时候就遇到了这个问题 折腾了一会才解决的!
SrpingCloud 之SrpingCloud config分布式配置中心搭建的更多相关文章
- SrpingCloud 之SrpingCloud config分布式配置中心
Config架构 当一个系统中的配置文件发生改变的时候,我们需要重新启动该服务,才能使得新的配置文件生效,spring cloud config可以实现微服务中的所有系统的配置文件的统一管理,而且还可 ...
- SrpingCloud 之SrpingCloud config分布式配置中心实时刷新
默认情况下是不能及时获取变更的配置文件信息 Spring Cloud分布式配置中心可以采用手动或者自动刷新 1.手动需要人工调用接口 监控中心 2.消息总线实时通知 springbus 动态刷新 ...
- SpringCloud与微服务Ⅹ --- SpringCloud Config分布式配置中心
一.SpringCloud Config是什么 分布式系统面临的问题 --- 配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务.由于每个 ...
- Spring Cloud Config 分布式配置中心使用教程
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...
- Spring Cloud Config 分布式配置中心【Finchley 版】
一. 介绍 1,为什么需要配置中心? 当服务部署的越来越多,规模越来越大,对应的机器数量也越来越庞大,靠人工来管理和维护服务的配置信息,变得困难,容易出错. 因此,需要一个能够动态注册和获取服务信息的 ...
- java框架之SpringCloud(7)-Config分布式配置中心
前言 分布式系统面临的配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中标会出现大量的服务.由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动 ...
- SpringCloud学习笔记(九):SpringCloud Config 分布式配置中心
概述 分布式系统面临的-配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务.由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动 ...
- SpringCloud2.0 Config 分布式配置中心 基础教程(十一)
Spring Cloud Config 简介 Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持.使用Config Server,您可以在所有环境中管理应用程序的外 ...
- SpringCloud学习之Config分布式配置中心(八)
统一配置中心概述 如果微服务架构中没有使用统一配置中心时,所存在的问题: 配置文件分散在各个项目里,不方便维护 配置内容安全与权限,实际开发中,开发人员是不知道线上环境的配置的 更新配置后,项目需要重 ...
随机推荐
- Eclipse个最实用的快捷键
一个Eclipse骨灰级开发人员总结了他觉得最实用但又不太为人所知的快捷键组合.通过这些组合能够更加easy的浏览源码,使得总体的开发效率和质量得到提升. 1. ctrl+shift+r:打开 ...
- linux bash shell run ros launch file and multi_node
#!/bin/bash #source /opt/ros/melodic/setup.bash #source /home/pi/catkin_ws/devel/setup.bash #ROS_PAC ...
- JavaScript 中的命名空间
全局变量应该由有系统范围相关性的对象们保留,并且它们的命名应该避免含糊并尽量减少命名冲突的风险.在实践中,这意味着你应该避免创建全局对象,除非它们是绝对必须的. 所以你对此是怎么做的?传统方法告诉我们 ...
- ppm\pgm格式
PGM 是便携式灰度图像格式(portable graymap file format),在黑白超声图像系统中经常使用PGM格式的图像.文件的后缀名为".pgm". PGM格式图像 ...
- poj 2553 The Bottom of a Graph(强连通、缩点、出入度)
题意:给出一个有向图G,寻找所有的sink点.“sink”的定义为:{v∈V|∀w∈V:(v→w)⇒(w→v)},对于一个点v,所有能到达的所有节点w,都能够回到v,这样的点v称为sink. 分析:由 ...
- HDFS源码分析数据块复制选取复制源节点
数据块的复制当然需要一个源数据节点,从其上拷贝数据块至目标数据节点.那么数据块复制是如何选取复制源节点的呢?本文我们将针对这一问题进行研究. 在BlockManager中,chooseSourceDa ...
- Apache中KeepAlive 配置
引子 先来分析一个Yslow 测试的一个页面的前端性能. 这里所有的请求是指http请求,对于一个请求各个阶段的划分,阻挡->域名解析->建立连接->发送请求->等待响应-&g ...
- LNMP环境搭建之php安装,wordpress博客搭建
LNMP环境搭建之php安装,wordpress博客搭建 一.介绍: 1.什么是CGI CGI全称是"通用网关接口"(Common Gateway Interface),HTTP服 ...
- IEnumerable, IEnumerator接口
IEnumerable接口 // Exposes the enumerator, which supports a simple iteration over a non-generic collec ...
- 在Linux下搭建Git服务器步骤
环境: 服务器 CentOS6.6 + git(version 1.7.1) 客户端 Windows10 + git(version 2.8.4.windows.1) ① 安装 Git Linux ...