SpringCloud 配置中心

本文详细介绍了Spring Cloud配置中心的使用,包括config-server的搭建、config-client的配置,以及如何修改配置中心端口。文章还提到了将配置中心服务化,探讨了接入Consul和Nacos作为注册中心的可能性,最后讨论了Nacos作为配置中心的注意事项。
摘要由CSDN通过智能技术生成

在微服务架构中,每一个服务都有自己的配置文件,这些配置文件还会因为生产、测试环境的不同而分为多个。某些配置项是相同的,某些配置项又是不同的,这给服务的部署和管理造成了一些困难。

Config Center 可以解决这些问题。

通过将配置文件统一放到某个地方(通常是 GitHub),然后让 配置中心 来统一读取、刷新配置信息。

Spring Cloud 提供了 Spring Cloud Config 来提供这一功能。

本节介绍一下 Spring Cloud Config 的使用。本节源码在 https://github.com/laolunsi/spring-boot-examples 中。


config-sever

首先创建一个父级 maven 项目,取名 spring-cloud-config-example,添加 spring-cloud 依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.1.13.RELEASE</version>
        <relativePath />
    </parent>

    <groupId>com.example</groupId>
    <artifactId>spring-cloud-config-example</artifactId>
    <version>1.0.RELEASE</version>

    <properties>
        <spring-cloud.version>Greenwich.SR5</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值