一文带你弄明白Spring Cloud Config的配置中心,还不赶快来学

本文详细介绍了如何搭建和配置Spring Cloud Config Server,通过在启动类添加@EnableConfigServer注解,设置属性文件的位置,以及配置文件的存放规则。文章还提到了配置中心的访问方式,并强调了对并发编程理解的重要性。
摘要由CSDN通过智能技术生成

spring-cloud-config-server

其次,在所创建的Spring Boot程序的启动类上添加@EnableConfigServer注解,开启Config Server服务,代码如下:

@EnableConfigServer

@SpringBootApplication

public class Application {

public static void main(String[] args) {

new SpringApplicationBuilder(Application.class).

web(true).run(args);

}

}

最后,设置属性文件的位置。Spring Cloud Config提供本地存储配置的方式。在bootstrap启动属性文件中,设置属性spring.profiles.active=native,并且设置属性文件所在的位置,如下所示:

server:

port: 7788 #配置中心端口

spr Java开源项目【ali1024.coding.net/public/P7/Java/git】 ing:

application:

name: config-server #服务名称

profiles:

active: native #设置读取本地配置文件

cloud:

config:

server: native:

searchLocations: classpath:config/ #声明本地配置文件的存放位置

配置说明:

(1)spring.profiles.active=n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值