config配置总控中心的搭建

springcloud中的服务配置组件能够统一集中管理各个微服务的配置文件,这里介绍一下服务配置组件config关于配置总控中心的搭建

1 核心依赖
        <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>
2 properties文件的配置

要将该微服务与外部GitHub或者gitee仓库进行关联,要在properties文件中指定仓库的:

  • uri
  • 要搜索的目录
  • 分支
server.port=3344

spring.application.name=cloud-config-center

eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:7001/eureka

spring.cloud.config.server.git.uri=git仓库地址
spring.cloud.config.server.git.search-paths=git仓库中要搜索的目录
spring.cloud.config.label=分支名称
3 主启动类的配置
@SpringBootApplication
@EnableConfigServer
public class CloudConfigCenter3344Application {

    public static void main(String[] args) {
        SpringApplication.run(CloudConfigCenter3344Application.class, args);
    }

}
4 总结

完成以上配置后就可以通过

http://localhost:3344/分支名/文件名

的方式对仓库中的文件进行访问
比如
http://localhost:3344/master/config-dev.properties

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值