zoukankan      html  css  js  c++  java
  • spring-cloud 配置中心config-将配置文件配置到github中

    1.配置中心配置

    --启动类

    @SpringBootApplication
    @EnableEurekaClient//注册中心客户端
    @EnableConfigServer//配置服务端
    public class ConfigApplication1299 {

    public static void main(String[] args) {
    SpringApplication.run(ConfigApplication1299.class);
    }
    }
    --application.yml
    server:
    port: 1299
    eureka:
    client:
    service-url:
    defaultZone: http://localhost:7001/eureka
    instance:
    prefer-ip-address: true
    spring:
    application:
    name: aigou-config-server
    cloud:
    config:
    server:
    git:
    uri: https://github.com/db2king/aigou_config_application.git #github上的仓库地址
    username: yyy
    password: xxx

    --导包
    <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-client</artifactId>
    </dependency>
    <!--配置中心支持-->
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    2.服务提供者配置
    --启动类
    @SpringBootApplication//标识为springcloud项目
    @EnableEurekaClient//eureka的客户端
    public class PlatApplication8001 {

    public static void main(String[] args) {
    SpringApplication.run(PlatApplication8001.class);
    }
    }
    --bootstrap.yml
    spring:
    cloud:
    config:
    uri: http://127.0.0.1:1299 #配置服务器
    label: master #分支
    name: plat-provider-application #github上面名称
    profile: test #环境

    3.将服务提供者的配置文件配置到github中
      spring:
      profiles:
      active: dev
      ---
      server:
      port: 8001
      spring:
      application:
      name: AIGOU-PLAT #不要使用下划线
      profiles: dev
      eureka:
      client:
      service-url:
      defaultZone: http://localhost:7001/eureka #告诉服务提供者要把服务注册到哪儿,注册中心的地址
      ---
      server:
      port: 8002
      spring:
      application:
      name: AIGOU-PLAT-test #不要使用下划线
      profiles: test
      eureka:
      client:
      service-url:
      defaultZone: http://localhost:7001/eureka #告诉服务提供者要把服务注册到哪儿,注册中心的地址

    注意事项

    配置中心配置文件的url地址是github仓库地址

    服务者配置文件中的name是github中yml的配置文件名字

  • 相关阅读:
    NJUPT_Wrj 个人训练实录
    图片保存本地,上传阿里云,保存该图片 在阿里云的 路径 到 本地数据库
    微信所有国家列表
    YII load()
    ab命令压力测试
    fatal: Could not read from remote repository
    JS获取URL中参数值的4种方法
    yii 生成 模型
    php子类是否自动调用父类构造函数
    自己实现一个简化版的SpringMVC框架
  • 原文地址:https://www.cnblogs.com/wgyi140724-/p/10613608.html
Copyright © 2011-2022 走看看