gpt4 book ai didi

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

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章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=nativespring.cloud.config.server.native.searchLocations=classpath:/config

3.加载 本地物理环境

spring.profiles.active=nativespring.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 svnspring.cloud.config.server.svn.uri=http://localhost:8080/dmeo/development/trunkspring.cloud.config.server.svn.username=xxxspring.cloud.config.server.svn.password=xxxspring.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: 8090spring:application:  name: configcloud:  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@EnableConfigServerpublic 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: 8090spring:application:  name: configcloud:  config:    server:      git:        uri: git@github.com:zhujin888/config-repo.git        username:         password:        basedir: D:\My_Java\anli\gitconfig\basedir  //配置本地git路径 把拉下来的配置文件存在这

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我.

原文链接:https://blog.csdn.net/liangweihua123/article/details/80914625 。

最后此篇关于Spring-cloud Config Server的3种配置方式的文章就讲到这里了,如果你想了解更多关于Spring-cloud Config Server的3种配置方式的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com