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 创建一个用于存放配置的项目
3.存放配置的项目的git地址 配置到项目的yml中
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上创建文件夹 用来存放配置信息
一般存三份
dev
:开发test
:测试pro
:生产
6.访问config server
两种方式: 随便用哪一种
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种配置方式 的全部内容, 来源链接: utcz.com/p/249316.html