热门标签 | HotTags
当前位置:  开发笔记 > 运维 > 正文

springboot配置文件抽离git管理统配置中心详解

在本篇文章里小编给大家整理的是关于springboot配置文件抽离git管理统配置中心的相关知识点内容,有需要的朋友们可以学习下。

springboot配置文件抽离,便于服务器读取对应配置文件,避免项目频繁更改配置文件,影响项目的调试与发布

1.创建统一配置中心项目conifg

1)pom配置依赖


  org.springframework.boot
  spring-boot-starter-parent
  2.0.6.RELEASE
   



  UTF-8
  UTF-8
  1.8
  Finchley.SR2



  
    org.springframework.cloud
    spring-cloud-config-server
  
  
    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-client
  

  
    org.springframework.boot
    spring-boot-starter-test
    test
  

  
    org.springframework.cloud
    spring-cloud-starter-bus-amqp
  

  
    org.springframework.cloud
    spring-cloud-config-monitor
  



  
    
      org.springframework.cloud
      spring-cloud-dependencies
      ${spring-cloud.version}
      pom
      import
    
  

2)yml文件配置

spring:
 application:
  name: config
 cloud:
  config:
   server:
    git:
     uri: https://gitee.com/XXXX/XXXXXX.git
     username: XXXXXXX
     password: XXXXXXXXX
eureka:
 client:
  service-url:
   defaultZone: http://localhost:8000/eureka/
management:
 endpoints:
  web:
   expose: "*"

2.创建git私有项目config-repo 用于存放配置文件

3.配置项目 可以看到对应的配置文件内容

http://localhost:8002/XXXXX/user-dev.yml

4.配置客户端读取配置文件

1)客户端配置pom


  org.springframework.cloud
  spring-cloud-config-client

2)客户端yml文件配置

spring:
 application:
  name: XXXXXX
 cloud:
  config:
   discovery:
    enabled: true
    service-id: CONFIG
   profile: dev



eureka:
 client:
  service-url:
   defaultZone: http://localhost:8000/eureka/
 instance:
  prefer-ip-address: true
  lease-renewal-interval-in-seconds: 1 # 单机时关闭eureka 保护模式
  lease-expiration-duration-in-seconds: 2

以上就是本次介绍的关于springboot配置文件抽离 git管理统 配置中心全部知识点内容,感谢大家对的支持。


推荐阅读
author-avatar
热情article文章_673_621
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有