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 相关文章推荐
浅谈@Value和@Bean的执行顺序问题
Jun 16 Java/Android
SpringCloud Alibaba项目实战之nacos-server服务搭建过程
Jun 21 Java/Android
启动Tomcat时出现大量乱码的解决方法
Jun 21 Java/Android
springcloud之Feign超时问题的解决
Jun 24 Java/Android
springboot集成springCloud中gateway时启动报错的解决
Jul 16 Java/Android
Java设计模式中的命令模式
Apr 28 Java/Android
java开发双人五子棋游戏
May 06 Java/Android
Java死锁的排查
May 11 Java/Android
JAVA springCloud项目搭建流程
May 11 Java/Android
Spring 使用注解开发
May 20 Java/Android
springboot读取nacos配置文件
May 20 Java/Android
Java中的Kafka为什么性能这么快及4大核心详析
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
c#中的实现php中的preg_replace
2009/12/21 PHP
PHP 批量更新网页内容实现代码
2010/01/05 PHP
php注销代码(session注销)
2012/05/31 PHP
php实现webservice实例
2014/11/06 PHP
php中get_magic_quotes_gpc()函数说明
2017/02/06 PHP
php二维码生成以及下载实现
2017/09/28 PHP
PHP共享内存使用与信号控制实例分析
2018/05/09 PHP
PHP CURL中传递cookie的方法步骤
2019/05/09 PHP
键盘控制事件应用教程大全
2006/11/24 Javascript
jQuery实现的多选框多级联动插件
2014/05/02 Javascript
js闭包实现按秒计数
2015/04/23 Javascript
JS实现网页游戏中滑块响应鼠标点击移动效果
2015/10/19 Javascript
jQuery循环遍历子节点并获取值的方法
2016/04/14 Javascript
JSON字符串转换JSONObject和JSONArray的方法
2016/06/03 Javascript
Js 获取当前函数参数对象的实现代码
2016/06/20 Javascript
js记录点击某个按钮的次数-刷新次数为初始状态的实例
2017/02/15 Javascript
js中开关变量使用实例
2017/02/24 Javascript
从对象列表中获取一个对象的方法,依据关键字和值
2017/09/20 Javascript
EasyUI框架 使用Ajax提交注册信息的实现代码
2017/09/27 Javascript
js实现类似iphone的网页滑屏解锁功能示例【附源码下载】
2019/06/10 Javascript
[03:23:49]2016.12.17日完美“圣”典全回顾
2016/12/19 DOTA
Python中利用函数装饰器实现备忘功能
2015/03/30 Python
简单谈谈Python中的json与pickle
2017/07/19 Python
windows环境下tensorflow安装过程详解
2018/03/30 Python
numpy中矩阵合并的实例
2018/06/15 Python
Python 3.8 新功能全解
2019/07/25 Python
opencv实现简单人脸识别
2021/02/19 Python
django使用F方法更新一个对象多个对象字段的实现
2020/03/28 Python
Python reduce函数作用及实例解析
2020/05/08 Python
canvas绘图按照contain或者cover方式适配并居中显示
2019/02/18 HTML / CSS
应用心理学个人求职信范文
2013/12/11 职场文书
澳大利亚商务邀请函
2014/01/17 职场文书
幸福家庭事迹材料
2014/02/03 职场文书
农民工工资支付承诺函
2014/03/31 职场文书
学校党员对照检查材料
2014/08/28 职场文书
2015年教师党员公开承诺书
2015/01/22 职场文书