git的远程配置拉取

目录

详细流程

创建一个git地址,

在idea里面创建一个配置中心(config_service)

 创建其他服务模块

创建zuul模块

导包

创建启动类


详细流程

创建一个git地址

创建需要读取的application-dev.yml  &  application-eureka-dev.yml 等文件  dev是环境名,前面是名字,后面有用

在idea里面创建一个配置中心(config_service)

  •       导包

    <dependencies>
        <!--springboot支持-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <!--config client端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <!--配置中心支持-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
    </dependencies>
  •   配置application.yml文件

 创建的时候选择开源,我们这里就不需要设置密码  否则我们需要设置密码

server:
  port: 5050
spring:
  application:
    name: gift-config
  cloud:
    config:
      server:
        git:
          uri:  git仓库地址,第一步说的创建的git地址  #开源不需要密码
#          username: *******  git账号
#          password: ******   git密码

          search-paths:   src/main/resources # 如果不是在根路径下面需要加入搜索地址

  • 创建启动类 注意加 @EnableConfigServer  注解

@SpringBootApplication
@EnableConfigServer //启用配置服务端
public class ConfigApp {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApp.class,args);
    }
}

配置完成,访问http://localhost:5050/  localhost:5050/application/devhttp://localhost:5050/  本地地址+端口+git里面的文件名+环境名  ,看到以下就说明搭建成功 

 创建其他服务模块

创建zuul模块

导包

    <dependencies>
        <!--springboot支持-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!--eureka-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <!--configclient端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>


    </dependencies>

创建 bootstrap.yml

这里特别注意,不能创建application.yml文件,而是创建 bootstrap.yml (区别自行百度)

spring:
  application:
    name: zuul-server  #应用配置名称
  profiles:
    active: dev #默认启动是dev
  cloud:
    config:
      profile: ${spring.profiles.active} #环境 java -jar -d spring.profiles.active=test gift-eureak.jar
      name: application-zuul #gitee上面自己的yml名称
      label: master #分支
      uri: http://127.0.0.1:5050  #去找config服务器配置,相当于连上仓库曹






创建启动类

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

以下是git仓库的yml参考

application-zuul-dev.yml

server:
  port: 4040
spring:
  application:
    name: zuul-gateway
  datasource:
    # 数据源配置
    password: 123456
    username: root
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/nanfang?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true

eureka:
  client:
    service-url:
      defaultZone: http://localhost:1010/eureka,
                   http://localhost:1020/eureka,
                   http://localhost:1030/eureka   #注册中心的地址  集群
  instance:
#    instance-id:
    prefer-ip-address: true
#zuul:
#  routes:
#    # serviceId和Path是一组的 这两个结合在一起的意思是: 要把urL路径中以/user/打头的请求
#    #分发给user-service 服务处理
#    #前面的前缀是可以随便写的,只要一样就是一对的
#    user.serviceId: user-server #用户名
#    user.path: /user/**
#    move.serviceId: move-server
#    move.path: /move/**
#  ignored-services: "*"  #忽略服务名访问,不可以通过服务名访问
#  prefix: "/apis"  #统一前缀,前端在调后端时,不管调哪一个服务,都要加一个apis

zuul:
  routes:
    user.serviceId: user-server
    user.path: /user/**
    move.serviceId: move-server
    move.path: /move/**
  ignored-services: "*"
  prefix: "/apis"

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值