Spring Cloud Config:基于JDBC搭建配置中心

为什么使用配置中心

每个微服务都有各种环境的配置,例如开发、测试、预生产、生产环境,通过配置中心可以集中进行管理与维护,同时还可以保证配置信息的安全性。

配置中心的特点

Spring Cloud Config分为服务端与客户端两部分:

  • 服务端:也称为分布式配置中心,是一个独立的微服务应用,用来连接配置仓库并为客户端提供获取配置信息的接口。
  • 客户端:是微服务架构中各微服务应用,启动时先从配置中心加载配置信息。
    在这里插入图片描述
config支持的存储方式
  • Git
  • FileSystem
  • Vault
  • JDBC
  • Redis
  • Aws S3
  • CredHub

本文搭建基于数据库存储的config配置中心

1、config server 服务端搭建

Application启动类增加注解 @EnableConfigServer

@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class ConfigServerDemoApplication {
   
    public static void main(String[] args) {
   
        SpringApplication.run(ConfigServerDemoApplication.class, args);
    }
}

pom引入maven依赖

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.3.0.RELEASE</version>
   <relativePath/>
</parent>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
</properties>

<dependencies>
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
     </dependency>

     <!--配置中心server依赖-->
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-config-server</artifactId>
     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值