Spring-cloud Config Server的3种配置方式


Posted in Java/Android onSeptember 25, 2021

Spring-cloud Config Server的3种配置

Spring-cloud Config Server 有多种种配置方式,今天我就在此介绍一下Git,local,svn三种配置方式,不过官方文档还是建议使用Git这种方式进行配置开发。

好的,现在开始!!!!!!!

1.config 默认Git加载

通过spring.cloud.config.server.git.uri指定配置信息存储的git地址,比如:https://github.com/xxx/config-repo

2.加载本地开发环境

spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config

3.加载 本地物理环境

spring.profiles.active=native
spring.cloud.config.server.native.searchLocations= file:E:\\Java\\config

4.加载svn环境

http://localhost:8080/{application}/{profile}/{label},比如:http://localhost:8080/dmeo/development/trunk

### config server svn
spring.cloud.config.server.svn.uri=http://localhost:8080/dmeo/development/trunk
spring.cloud.config.server.svn.username=xxx
spring.cloud.config.server.svn.password=xxx
spring.profiles.active=subversion

PS: svn 环境 需要 引入 SVN jar包

<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>

springcloud统一配置中心(config server 端)

1.为什么要使用统一配置中心?

1.配置不方便维护

2.配置内容的安全性和权限

3.更新配置项目需要重启

2.登陆github 创建一个用于存放配置的项目

Spring-cloud Config Server的3种配置方式

Spring-cloud Config Server的3种配置方式

3.存放配置的项目的git地址 配置到项目的yml中

Spring-cloud Config Server的3种配置方式 

4.项目中的配置(Spring Cloud Config server 端)

该项目即是eureka的客户端 又是Config的服务端

<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.zhu</groupId>
    <artifactId>config</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RELEASE</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-test</artifactId>
            <scope>test</scope>
        </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>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
</project>

yml配置

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8085/eureka/
server:
  port: 8090
spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: git@github.com:zhujin888/config-repo.git //git地址
          username: git的账号
          password: git的密码

主类:

package com.zhu.config;
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;
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

5.再git上创建文件夹 用来存放配置信息

Spring-cloud Config Server的3种配置方式

一般存三份

  • dev:开发
  • test:测试
  • pro:生产

Spring-cloud Config Server的3种配置方式

6.访问config server

两种方式: 随便用哪一种

Spring-cloud Config Server的3种配置方式

7.把远端的git拉到本地的git来

配置本地 git路径

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8085/eureka/
server:
  port: 8090
spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: git@github.com:zhujin888/config-repo.git
          username: 
          password:
          basedir: D:\My_Java\anli\gitconfig\basedir  //配置本地git路径 把拉下来的配置文件存在这

以上为个人经验,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Java/Android 相关文章推荐
Java实现简易的分词器功能
Jun 15 Java/Android
Java中常用解析工具jackson及fastjson的使用
Jun 28 Java/Android
Java集成swagger文档组件
Jun 28 Java/Android
java设计模式--三种工厂模式详解
Jul 21 Java/Android
spring cloud 配置中心native配置方式
Sep 25 Java/Android
利用Sharding-Jdbc进行分库分表的操作代码
Jan 22 Java/Android
Spring依赖注入多种类型数据的示例代码
Mar 31 Java/Android
Java 超详细讲解十大排序算法面试无忧
Apr 08 Java/Android
SpringCloud项目如何解决log4j2漏洞
Apr 10 Java/Android
Android RecyclerView实现九宫格效果
Jun 28 Java/Android
Java中的Kafka为什么性能这么快及4大核心详析
Sep 23 Java/Android
Android移动应用开发指南之六种布局详解
Sep 23 Java/Android
MyBatis-Plus 批量插入数据的操作方法
Sep 25 #Java/Android
spring cloud 配置中心native配置方式
Sep 25 #Java/Android
spring cloud 配置中心客户端启动遇到的问题
Sep 25 #Java/Android
SpringBoot+Vue+JWT的前后端分离登录认证详细步骤
Sep 25 #Java/Android
java如何实现socket连接方法封装
Sep 25 #Java/Android
IDEA2021.2配置docker如何将springboot项目打成镜像一键发布部署
Java数据开发辅助工具Docker与普通程序使用方法
Sep 15 #Java/Android
You might like
综合图片计数器
2006/10/09 PHP
php中将地址生成迅雷快车旋风链接的代码[测试通过]
2011/04/20 PHP
PHP下使用CURL方式POST数据至API接口的代码
2013/02/14 PHP
php获取文件大小的方法
2014/02/26 PHP
PHP命名空间(namespace)的使用基础及示例
2014/08/18 PHP
PHP实现图片防盗链破解操作示例【解决图片防盗链问题/反向代理】
2020/05/29 PHP
可以文本显示的公告栏的js代码
2007/03/11 Javascript
innerhtml用法 innertext用法 以及innerHTML与innertext的区别
2009/10/26 Javascript
javascript 事件处理、鼠标拖动效果实现方法详解
2012/05/11 Javascript
javascript实现下班倒计时效果的方法(可桌面通知)
2015/07/10 Javascript
JS实现弹性菜单效果代码
2015/09/07 Javascript
jQuery自定义动画函数实例详解(附demo源码)
2015/12/10 Javascript
JavaScript高级程序设计(第三版)学习笔记1~5章
2016/03/11 Javascript
基于jQuery实现收缩展开功能
2016/03/18 Javascript
JS实现iframe编辑器光标位置插入内容的方法(兼容IE和Firefox)
2016/06/24 Javascript
JS版微信6.0分享接口用法分析
2016/10/13 Javascript
[原创]javascript typeof id==='string'?document.getElementById(id):id解释
2016/11/02 Javascript
vue router2.0二级路由的简单使用
2017/07/05 Javascript
jQuery+HTML5实现WebGL高性能烟花绽放动画效果【附demo源码下载】
2017/08/18 jQuery
Vue.set() this.$set()引发的视图更新思考及注意事项
2018/08/30 Javascript
详解Python的Twisted框架中reactor事件管理器的用法
2016/05/25 Python
python中的lambda表达式用法详解
2016/06/22 Python
k-means 聚类算法与Python实现代码
2020/06/01 Python
美国打印机墨水和碳粉购物网站:QuikShip Toner
2018/08/29 全球购物
计算机专业毕业生自我鉴定
2014/01/16 职场文书
好习惯伴我成长演讲稿
2014/05/21 职场文书
采购部长岗位职责
2014/06/13 职场文书
校本研修个人总结
2015/02/28 职场文书
出国留学单位推荐信
2015/03/26 职场文书
停电通知范文
2015/04/16 职场文书
公司更名通知函
2015/04/24 职场文书
党员干部公开承诺书范文
2015/04/27 职场文书
欠款起诉书范文
2015/05/19 职场文书
Python合并pdf文件的工具
2021/07/01 Python
mysql聚集索引、辅助索引、覆盖索引、联合索引的使用
2022/02/12 MySQL
SQL Server中常用截取字符串函数介绍
2022/03/16 SQL Server