【SrpingCloud】四、将项目的配置放置到远程的Github进行管理

一、编写好配置文件并上传到github或码云,并获取 HTTPS 链接

  • 配置文件
    • 默认激活:dev
    • 状态一:dev
    • 状态二:test
spring:
  profiles:
    active: dev
---
server:
  port: 8201
spring:
  profiles: dev
  application:
    name: springloud-provider-dept-dev
eureka:
    client:
      service-url:
        defaultZone: http://uereka7001.com:7001/eureka/
---
server:
  port: 8202
spring:
  profiles: test
  application:
    name: springloud-provider-dept-test
eureka:
  client:
    service-url:
      defaultZone: http://uereka7001.com:7001/eureka/

在这里插入图片描述

二、连接git上的配置文件

  1. 新建 Module 名为:springcloud-config-server-3344,连接远程仓库,获取git上的配置信息
  • 添加依赖
<dependencies>
        <!--        springboot的web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!--        actuator 完善监控信息-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!--config-server-->
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-config-server -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>

    </dependencies>
  1. 编写配置信息
server:
  port: 3344

spring:
  application:
    name: springcloud-config-server
#    连接远程仓库
#    通过 config-server 可以连接到git,访问其中的资源以及配置
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/hikiea/springcloud-config.git
  1. 编写启动类,@EnableConfigServer 开启远程服务配置配置
@SpringBootApplication
@EnableConfigServer
public class Config_Server_3344 {
    public static void main(String[] args) {
        SpringApplication.run(Config_Server_3344.class,args);
    }
}

三、把配置文件应用到服务端

  1. 建立配置文件:Bootstrap.yml
  • name: git上的配置文件名字
  • label:分支
  • profile:需要激活的部分
  • uri:连接远程仓库的Module的uri
spring:
  cloud:
    config:
      name: config-dept
      label: master
      profile: dev
      uri: http://localhost:3344

四、连接完成,可以正常实现接口

发布了28 篇原创文章 · 获赞 4 · 访问量 1307

猜你喜欢

转载自blog.csdn.net/weixin_44100826/article/details/104945611
今日推荐