• springcloud之配置中心用法


    一、配置文件服务器server端

    1、构建server端所需jar

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

     2、构建server端main方法所在类的注解

    @SpringBootApplication
    @EnableConfigServer
    @EnableEurekaClient
    @EnableAutoConfiguration
    @Configuration

    3、构建server端所需配置文件及详解

    server:
      port: 8001  
    spring:
      application:
        name: spring-cloud-config-server
      cloud:
        config:
          server:
            git:
              uri: https://github.com/Pinshuducha/config-file/ --git仓库地址
              search-paths: config-repo --将拉取到的配置文件放到哪个文件夹下
              username:   --git用户名 有时可以不加
              password:   --git密码  有时可以不加
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8000/eureka/

    二、配置文件服务器client端

    1、构建client端所需jar

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.4.RELEASE</version>
        </dependency>
        <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>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

    2、构建client端所需配置文件及解释(注意:此时的配置文件一般命名为bootstrap.yml)

    server:
      port: 8002
    spring:
      application:
        name: configclient
      cloud:
        config:
          discovery:
            serviceId: spring-cloud-config-server
            enabled: true
          name: configclient
          profile: default,pre,two
          label: master
      profiles:
        active: default,pre,two
    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8000/eureka/
    

    3、构建client端所需注解

    @SpringBootApplication
    @EnableEurekaClient

    三、配置文件库

    这个是我创建配置文件库的方法

    直接操作github或gitlib的操作页面创建,然后更新到本地,以后就可以修改了

    server端和client端代码参考:https://github.com/Pinshuducha/spring-cloud-config.git

    配置文件库参考:https://github.com/Pinshuducha/config-file.git

  • 相关阅读:
    jQuery实现radio第一次点击选中第二次点击取消功能(转)
    好用的文件下载类
    Windows获取远程Linux局域网内的mysql连接
    linux通过端口号查找程序执行路径
    linux几个命令
    java判断是移动端还是pc端
    jsp传给java属性,java生成json串,方便以后取出来
    如何在线程中获取spring 管理的bean
    [DeploymentService:290066]Error occurred while downloading files from admin server for deployment request "0". Underlying error is: "null"
    double,失去精度
  • 原文地址:https://www.cnblogs.com/lu51211314/p/10370168.html
Copyright © 2020-2023  润新知