Spring-cloudConfigServer的3种配置⽅式
⽬录
Spring-cloud Config Server的3种配置
2.加载本地开发环境
3.加载本地物理环境
4.加载svn环境
springcloud统⼀配置中⼼(config server 端)
1.为什么要使⽤统⼀配置中⼼?
2.登陆github 创建⼀个⽤于存放配置的项⽬
3.存放配置的项⽬的git地址配置到项⽬的yml中
4.项⽬中的配置(Spring Cloud Config server 端)
5.再git上创建⽂件夹⽤来存放配置信息
6.访问config server
7.把远端的git拉到本地的git来
Spring-cloud Config Server的3种配置
Spring-cloud Config Server 有多种种配置⽅式,今天我就在此介绍⼀下Git,local,svn三种配置⽅式,不过官⽅⽂档还是建议使⽤Git这种⽅式进⾏配置开发。好的,现在开始
2.加载本地开发环境
spring.profiles.active=native
fig.server.native.searchLocations=classpath:/config
3.加载本地物理环境
springcloud难学吗spring.profiles.active=native
fig.server.native.searchLocations= file:E:\\Java\\config
4.加载svn环境
### config server svn
fig.server.svn.uri=localhost:8080/dmeo/development/trunk
fig.server.svn.username=xxx
fig.server.svn.password=xxx
spring.profiles.active=subversion
PS: svn 环境需要引⼊ SVN jar包
<groupId&atesoft.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="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /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>repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
yml配置
eureka:
client:
service-url:
defaultZone: localhost:8085/eureka/
server:
port: 8090
spring:
application:
name: config
cloud:
config:
server:
git:
uri: git@github:zhujin888/config-repo.git //git地址
username: git的账号
password: git的密码
主类:
package fig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.fig.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: localhost:8085/eureka/
server:
port: 8090
spring:
application:
name: config
cloud:
config:
server:
git:
uri: git@github:zhujin888/config-repo.git
username:
password:
basedir: D:\My_Java\anli\gitconfig\basedir //配置本地git路径把拉下来的配置⽂件存在这以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论