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

yipeiwu_com5年前Python基础

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

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

1)pom配置依赖

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.6.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
  <spring-cloud.version>Finchley.SR2</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>

  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bus-amqp</artifactId>
  </dependency>

  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-monitor</artifactId>
  </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>

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

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-config-client</artifactId>
</dependency>

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管理统 配置中心全部知识点内容,感谢大家对【听图阁-专注于Python设计】的支持。

相关文章

python 一篇文章搞懂装饰器所有用法(建议收藏)

python 一篇文章搞懂装饰器所有用法(建议收藏)

01. 装饰器语法糖 如果你接触 Python 有一段时间了的话,想必你对 @ 符号一定不陌生了,没错 @ 符号就是装饰器的语法糖。 它放在一个函数开始定义的地方,它就像一顶帽子一样戴...

python利用Guetzli批量压缩图片

python利用Guetzli批量压缩图片

Google 又开源了,这次开源了一款图像算法工具 Guetzli。Guetzli,在瑞士德语中是“cookie(曲奇)”的意思,是一个针对数码图像和网页图像的 JPEG 编码器,能够通...

关于Pytorch的MLP模块实现方式

关于Pytorch的MLP模块实现方式

MLP分类效果一般好于线性分类器,即将特征输入MLP中再经过softmax来进行分类。 具体实现为将原先线性分类模块: self.classifier = nn.Linear(con...

Python基础知识点 初识Python.md

Python基础知识点 初识Python.md

Python简介 Python的历史 1989年圣诞节:Guido von Rossum开始写Python语言的编译器。 1991年2月:第一个Python编译器(同时也是解释器)...

Java及python正则表达式详解

Java及python正则表达式详解

正则表达式语法及常用元字符: 正则表达式有元字符及不同组合来构成,通过巧妙的构造正则表达式可以匹配任意字符串,并完成复杂的字符串处理任务。 常用的元字符有: 其中在使用反斜线时要注意:如...