温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Spring-cloud Config Server的3种配置方式是怎样的

发布时间:2021-09-26 10:05:01 来源:亿速云 阅读:198 作者:柒染 栏目:开发技术

今天就跟大家聊聊有关Spring-cloud Config Server的3种配置方式是怎样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获

Spring-cloud Config Server的3种配置

Spring-cloud Config Server 有多种种配置方式,今天我就在此介绍一下Git,local,svn三种配置方式,不过官方文档还是建议使用Git这种方式进行配置开发。

好的,现在开始!!!!!!!

1.config 默认Git加载

通过spring.cloud.config.server.git.uri指定配置信息存储的git地址,比如:https://github.com/xxx/config-repo

2.加载本地开发环境

spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/config

3.加载 本地物理环境

spring.profiles.active=native
spring.cloud.config.server.native.searchLocations= file:E:\\Java\\config

4.加载svn环境

http://localhost:8080/{application}/{profile}/{label},比如:http://localhost:8080/dmeo/development/trunk

### config server svn
spring.cloud.config.server.svn.uri=http://localhost:8080/dmeo/development/trunk
spring.cloud.config.server.svn.username=xxx
spring.cloud.config.server.svn.password=xxx
spring.profiles.active=subversion

PS: svn 环境 需要 引入 SVN jar包

<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>

springcloud统一配置中心(config server 端)

1.为什么要使用统一配置中心?

1.配置不方便维护

2.配置内容的安全性和权限

3.更新配置项目需要重启

2.登陆github 创建一个用于存放配置的项目

Spring-cloud Config Server的3种配置方式是怎样的

Spring-cloud Config Server的3种配置方式是怎样的

3.存放配置的项目的git地址 配置到项目的yml中

Spring-cloud Config Server的3种配置方式是怎样的 

4.项目中的配置(Spring Cloud Config server 端)

该项目即是eureka的客户端 又是Config的服务端

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.zhu</groupId>
    <artifactId>config</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
</project>

yml配置

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8085/eureka/
server:
  port: 8090
spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: git@github.com:zhujin888/config-repo.git //git地址
          username: git的账号
          password: git的密码

主类:

package com.zhu.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

5.再git上创建文件夹 用来存放配置信息

Spring-cloud Config Server的3种配置方式是怎样的

一般存三份

  • dev:开发

  • test:测试

  • pro:生产

Spring-cloud Config Server的3种配置方式是怎样的

6.访问config server

两种方式: 随便用哪一种

Spring-cloud Config Server的3种配置方式是怎样的

7.把远端的git拉到本地的git来

配置本地 git路径

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8085/eureka/
server:
  port: 8090
spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: git@github.com:zhujin888/config-repo.git
          username: 
          password:
          basedir: D:\My_Java\anli\gitconfig\basedir  //配置本地git路径 把拉下来的配置文件存在这

看完上述内容,你们对Spring-cloud Config Server的3种配置方式是怎样的有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI