今天就跟大家聊聊有关Spring-cloud Config Server的3种配置方式是怎样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获
Spring-cloud Config Server 有多种种配置方式,今天我就在此介绍一下Git,local,svn三种配置方式,不过官方文档还是建议使用Git这种方式进行配置开发。
好的,现在开始!!!!!!!
通过spring.cloud.config.server.git.uri指定配置信息存储的git地址,比如:https://github.com/xxx/config-repo
spring.profiles.active=native spring.cloud.config.server.native.searchLocations=classpath:/config
spring.profiles.active=native spring.cloud.config.server.native.searchLocations= file:E:\\Java\\config
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>
1.配置不方便维护
2.配置内容的安全性和权限
3.更新配置项目需要重启
该项目即是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); } }
一般存三份
dev
:开发
test
:测试
pro
:生产
两种方式: 随便用哪一种
配置本地 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种配置方式是怎样的有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。