美文网首页Java
springCloud项目实战托管config配置文件至gith

springCloud项目实战托管config配置文件至gith

作者: 黄黄丶 | 来源:发表于2019-10-18 09:54 被阅读0次

    养成良好的记录习惯
    作者:黄黄

    引入依赖

    config服务端引入依赖

       <!-- config专属依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-server</artifactId>
            </dependency>
    

    config客户端引入依赖

      <!-- config客户端依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-client</artifactId>
            </dependency>
    

    添加注解和配置

    @SpringBootApplication//springBoot基础依赖
    @EnableDiscoveryClient//eureka客户端依赖
    @EnableConfigServer//config服务端依赖
    public class ConfigApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ConfigApplication.class, args);
        }
    }
    

    操作github

    创建仓库和对应的配置文件

    image.png

    config服务端配置

    • 复制github配置文件存放页面地址进入config服务端application配置文件中加入配置
    spring:
      application:
        name: zzw-config
      cloud:
        config:
          server:
            git:
              #远程配置地址(git.码云等等平台)
              uri: https://github.com/zzw1314520/config
              #登陆平台用户名
              username: xxxx
              #登陆平台密码
              password: xxxxx
    #          指定拉取配置放取地址
    #          basedir:
    eureka:
      client:
        service-url:
          defaultZone: http://localhost:8761/eureka
    

    config客户端配置

    spring:
      application:
        name: zzw-order
      # 配置中心
      cloud:
        config:
          fail-fast: true
          name: ${spring.application.name}
          profile: ${spring.profiles.active}
          discovery:
            enabled: true
            service-id: zzw-config
      profiles:
        active: dev
    
    eureka:
      client:
        service-url:
          defaultZone: http://localhost:8761/eureka
    

    依次启动config服务端和客户端

    • 启动后config客户端就会加载github中application-dev.yml和zzw-order-dev.yml中的配置
      注:application-dev.yml中可定义各模块之间通用配置

    相关文章

      网友评论

        本文标题:springCloud项目实战托管config配置文件至gith

        本文链接:https://www.haomeiwen.com/subject/wigbmctx.html