zoukankan      html  css  js  c++  java
  • spring cloud config配置记录

    1. spring cloud config配置记录

    1.1. pom

    <!-- 分布式配置中心 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    

    1.2. 创建bootstrap.yml

    1. 配置eureka和config相关配合
    spring:
      application:
        name: carer
      cloud:
        config:
          uri: http://i.xxx.com:8888
          profile: dev
          username: dev
          password: xxxx
    eureka:
      instance:
        appname: carer-test
        prefer-ip-address: true
      client:
        serviceUrl:
          defaultZone: http://dev:xxxx@i.tzxylao.com:8761/eureka/
    
    1. 其他配置全部移至application-dev.properties和application.pro.properties

    1.3. 配置刷新

    1.3.1. 添加注解

    1. 添加@RefreshScope注解
    2. example
    @Component
    @RefreshScope
    public class SysConfig {
    
        @Value("${openTradeTest}")
        private String openTradeCode;
    
        @Value("${sysId}")
        private String sysId;
    
        @Value("${authUrl}")
        private String authUrl;
    
        public String getOpenTradeCode() {
            return openTradeCode;
        }
    
        public void setOpenTradeCode(String openTradeCode) {
            this.openTradeCode = openTradeCode;
        }
    
        public String getSysId() {
            return sysId;
        }
    }
    

    1.3.2. 添加pom

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    

    1.3.3. 配置

    spring.rabbitmq.virtual-host=xxx
    spring.rabbitmq.addresses=localhost:5672
    spring.rabbitmq.username=xxx
    spring.rabbitmq.password=***
    

    上述两个步骤在服务端和客户端都得做

    1.3.4. 刷新

    1. 调用 localhost:8888/bus/refresh 实现连接同一个服务的所有相同客户端配置刷新

    1.4. 自动刷新

    1.4.1. gitlab上配置


    2. 最后记得add Webhook按钮点下添加
    3. 因为设置了登录密码,填写地址的时候,可以这样

    http://username:password@localhost:8888/bus/refresh
    
  • 相关阅读:
    HTML元素解释
    Java命名规范
    HDU 1058 Humble Numbers(DP,数)
    HDU 2845 Beans(DP,最大不连续和)
    HDU 2830 Matrix Swapping II (DP,最大全1矩阵)
    HDU 2870 Largest Submatrix(DP)
    HDU 1421 搬寝室(DP)
    HDU 2844 Coins (组合背包)
    HDU 2577 How to Type(模拟)
    HDU 2159 FATE(二维完全背包)
  • 原文地址:https://www.cnblogs.com/sky-chen/p/10282093.html
Copyright © 2011-2022 走看看