• 第五篇 高可用配置中心config-server(SVN版)


    一 新建module引入config-server依赖

    <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-server</artifactId>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.tmatesoft.svnkit/svnkit 此处是从svn上读取配置文件要引入的依赖-->
            <dependency>
                <groupId>org.tmatesoft.svnkit</groupId>
                <artifactId>svnkit</artifactId>
            </dependency>
    </dependencies>

    当然还有eureka-client的依赖  我已经在父pom里引用过 此处就不再重复引用

    二 新建application.yml  内容如下

    server:
      port: 8064
    spring:
      application:
        name: config-server
      profiles:
        active: subversion #从svn上读取时必加
      cloud:
        config:
          server:
            svn:
              uri: svn://XXXXX/tms/tms-callcenter/config
              search-paths: "{application}" #使用{application}占位符 踩坑点 必须加" " 否则 不识别文件夹搜索
              default-label: trunk
              username: **
              password: **
    
    eureka:
      instance:
        prefer-ip-address: true
        instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
      client:
        serviceUrl:
          defaultZone: http://**:**@127.0.0.1:8060/eureka/

    此处有需要注意的几个地方 :

      1.spring.profiles.active=subversion

      2.svn上的default-label的默认是 trunk 

      3.要想分环境来读取配置文件  当search-paths 为 {application} 时 它是不识别文件夹的   只有加上“{application}"这样才会根据文件夹去搜索

    三 在启动类上加@EnableConfigServer

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

     四 去svn的路径中添加配置文件

    文件的大概路径如图所示 并把它传到svn上

    支持的配置文件格式有

    五 启动config-server 检验是否能读取到配置文件

    浏览器访问192.168.31.103:8061/{项目名称}/{环境}

     

    六 客户端从svn上读取配置文件

     

    必须新建bootstrap.yml文件  不然读取不到

    内容如下

    spring:
      application:
        name: callcenter-user
      profiles:
        active: subversion,dev
      cloud:
        config:
          name: {application}
          profile: test
          label: trunk
          retry:
            initial-interval: 2000
            max-attempts: 5
          discovery:
            enabled: true
            service-id: config-server
    eureka:
      client:
        serviceUrl:
          defaultZone: http://hmzj:123456@127.0.0.1:8060/eureka/
    logging:
      path: D:log
      file: ${spring.application.name}
      pattern:
        level: INFO

    根据profile 来定义环境 即可

  • 相关阅读:
    vue-面试
    使用webpack4搭建一个基于Vue的组件库
    vue 仿今日头条
    如何正确的在项目中接入微信JS-SDK
    vuejs实现折叠面板展开收缩动画
    Vue的watch和computed属性
    Android Studio(十):添加assets目录
    Android Studio(九):引用jar及so文件
    Android Studio(八):Android Studio设置教程
    Android Studio(七):项目从Eclipse到Android Studio迁移
  • 原文地址:https://www.cnblogs.com/pangyangqi/p/9446291.html
Copyright © 2020-2023  润新知