springcloud搭建配置中心config client服务(二)

搭建config client服务,从gitlab上拉取配置文件

在上一篇中iot创建一个maven modules,pom文件都一样

我取的项目名是iot-daemon-service项目

注意图中红色的部分,因为要通过iot-config服务去拉取gitlab上的配置信息

首先创建一个bootstrap.yml文件

spring:
  application:
    name: iot-daemon-service #服务名
  profiles:
    active: dev
  cloud:
    config:
      fail-fast: false
      discovery:
        service-id: iot-config-server
        enabled: true
      profile: ${spring.profiles.active} #iot-daemon-service-dev
      label: ${spring.profiles.active}  #dev分支上拉取配置名为iot-daemon-service-dev.yml
---
spring:
  profiles: dev
eureka:
  instance:
    prefer-ip-address: true
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 20
  client:
    serviceUrl:
      defaultZone: http://root:root@127.0.0.1:1025/eureka
    registry-fetch-interval-seconds: 10

1.加载顺序
这里主要是说明application和bootstrap的加载顺序。

bootstrap.yml(bootstrap.properties)先加载
application.yml(application.properties)后加载。
bootstrap.yml 用于应用程序上下文的引导阶段。

bootstrap.yml 由父Spring ApplicationContext加载。

父ApplicationContext 被加载到使用 application.yml 的之前。

启动类

package com.xhs.iot.daemon;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class IotDaemonServiceApplication {

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

}

要创建一个配置文件,我把配置文件放到了自己搭建的gitlab上

配置文件名称最好是和服务名称一样

内容就是定义了一个端口好

启动项目

我的端口号变为刚刚gitlab上定义的端口4060,说明拉取到了。

 

也可以在config service上查看是否拉取到了配置信息,浏览器输入config service端口号在加上在gitlab上定义的文件名

127.0.0.1:4001/iot-daemon-service-dev/dev/dev       iot-daemon-service-dev/dev 文件名称 后面的dev是该文件在哪个分支上dev分支

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值