Spring Cloud Config Server
spring cloud config server 官方文档
本地保存配置文件
先创建一个空项目
创建 config-server 作为Model创建
再创建 config-client 作为model 创建
以下是config-server的 build.gradle 文件
buildscript {ext {springBootVersion = '1.5.7.RELEASE'}repositories {mavenCentral()}dependencies {classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")}
}apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8repositories {mavenCentral()
}ext {springCloudVersion = 'Dalston.SR3'
}dependencies {compile('org.springframework.cloud:spring-cloud-config-server')testCompile('org.springframework.boot:spring-boot-starter-test')
}dependencyManagement {imports {mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"}
}
config-server 目录结构
package com.cn.nur;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerApplication.class, args);}
}
# 配置中心存储配置文件的方式
spring.profiles.active: native
# 应用名称
spring.application.name: config-server
# 端口
server.port: 8888
#本地配置文件存放路径 (${spring.profiles.active} 为native 是才有效)
spring.cloud.config.server.native.searchLocations: classpath:/config
启动config-server
启动成功
以下是configclient配置
buildscript {ext {springBootVersion = '1.5.7.RELEASE'}repositories {mavenCentral()}dependencies {classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")}
}apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8repositories {mavenCentral()
}ext {springCloudVersion = 'Dalston.SR3'
}dependencies {compile('org.springframework.cloud:spring-cloud-starter-config')compile('org.springframework.boot:spring-boot-starter-web')testCompile('org.springframework.boot:spring-boot-starter-test')
}dependencyManagement {imports {mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"}
}
package com.cn.nur;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class ConfigClientApplication {public static void main(String[] args) {SpringApplication.run(ConfigClientApplication.class, args);}
}
bootstrap读取顺序先于application.yml文件,所以bootstrap中指定配置中心地址
bootstrap.properties
# Flag to say that remote configuration is enabled. Default true;
spring.cloud.config.enabled=true
# Name of application used to fetch remote properties.
# 远程配置文件名称 如 service0-{profile}.properties
# @Value("${spring.application.name:application}")
#
spring.cloud.config.name=service0
# The URI of the remote server (default http://localhost:8888). 配置服务器
spring.cloud.config.uri=http://localhost:8888
# 要启用的环境(test,pro,dev 之类的) 配置服务器得有 ${spring.cloud.config.name}-{spring.cloud.config.profile}.properties文件
spring.cloud.config.profile=test
#spring.cloud.config.label=config-label-test
项目目录结构
启动config-client
说明配置文件已经从配置中心服务器获取
Spring Cloud Config Server相关推荐
- 为Spring Cloud Config Server配置远程git仓库
简介 虽然在开发过程,在本地创建git仓库操作起来非常方便,但是在实际项目应用中,多个项目组需要通过一个中心服务器来共享配置,所以Spring Cloud配置中心支持远程git仓库,以使分散的项目组更 ...
- java测试spring cloud_java – 从Spring引导单元测试中排除Spring Cloud Config Server
鉴于我有以下3豆: @Component public class ServiceConfig { // This value is only available from the Spring Cl ...
- Spring Cloud Config Server简介
1.概述 在本教程中,我们将回顾Spring Cloud Config Server的基础知识. 我们将设置一个Config Server ,然后构建一个客户端应用程序 ,该客户端应用程序在启动时会消 ...
- Spring Cloud教程– Spring Cloud Config Server简介
问题 SpringBoot在通过属性或YAML文件外部化配置属性方面提供了很大的灵活性. 我们还可以使用特定于配置文件的配置文件(例如application.properties , applicat ...
- 第十二章:Spring Cloud Config Server 的配置
###1.为什么要使用config 集中管理 不通环境不通配置 运行期间动态调整配置 自动刷新 ###2.用法入门 导入pom <dependency><groupId>org ...
- 位置穿越服务器,编写Spring Cloud Config Server路径穿越漏洞全面检测脚本
Spring Cloud Config Server路径穿越漏洞(CVE-2019-3799)的分析文章已经很多了,这里我不在画蛇填足.在分析该漏洞之后,发现了一些小细节,感觉对该漏洞检测还是挺有帮助 ...
- Spring Cloud Config Server迁移节点或容器化带来的问题
如果您跟我一样,目前正在使用Spring Cloud Config做为配置中心的话,本篇将来要描述的问题,强烈推荐了解和关注!因为这个问题目前存在于所有的版本中,还没有修复,需要注意避开或设法解决. ...
- Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务
上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...
- Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config,它支持配 ...
最新文章
- java http 上传_Java使用HttpURLConnection上传文件
- EL表达式中获取List中某个元素的值
- 网易云信携手“瑶台”,打造元宇宙商业化实践标杆案例
- tf.nn.dropout和tf.keras.layers.Dropout的区别(TensorFlow2.3)与实验
- java获取ResultSet长度
- 利用scp 远程上传下载文件/文件夹
- mc用云服务器搭建_最全的云服务器架设我的世界私服教程,不看后悔哦!
- 前端技术基础(一):浏览器相关
- idea快捷键整合-无鼠标操作idea
- mysql翻译逗号隔开的字典_【多测师小课堂】python数据类型之列表、字典、元祖、字符串...
- 【论文笔记】Recover Canonical-View Faces in the Wild with Deep Neural Network
- MyBatis教程(看这一篇就够了)
- 强制卸载mysql关联程序
- 推荐10个 Chrome 插件
- 职场上个人的核心技术_五年老员工被空降领导要求交出核心技术,拒绝后,隔天上班懵了...
- WLC-WLC升级(以2504为例)
- 【Pandas分组聚合】进阶:透视表、交叉表(pivot_table() 、crosstab())
- 笔记本键盘进水几个按键失灵 还能修好么_苹果首台笔记本Mac Portable全拆卸,蒂姆·库克签名,无螺丝设计,机械键盘...
- 百度搜素推出细雨算法
- Linux负载均衡脚本,linux负载均衡软件设置(一)
热门文章
- android没有输入焦点类控件的输入法调用,Android 手机下输入框获取焦点时, 输入法会挡住输入框...
- html怎么控制进度条,HTML如何实现进度条?附源码
- Java底层抛出异常_总结java的exception
- 完全开源版可乐个人发卡网无授权完整运营版/整合最新免签约支付接口
- 狂雨CMS小说网站源码 附一套pc模板和两套手机模板(白色,蓝色)
- Java连接Elasticsearch6.xxx 代码高亮显示篇四
- SQL Server 2000订阅与发布的具体操作
- 设计模式笔记[四种模式+四种原则]
- MySQL入门 (二) : SELECT 基础查询
- Swift与Objective-C的对比