Spring-cloud Config Server的3種配置方式
Spring-cloud Config Server的3種配置
Spring-cloud Config Server 有多種種配置方式,今天我就在此介紹一下Git,local,svn三種配置方式,不過官方文檔還是建議使用Git這種方式進行配置開發(fā)。
好的,現(xiàn)在開始!?。。。。?!
1.config 默認Git加載
通過spring.cloud.config.server.git.uri指定配置信息存儲的git地址,比如:https://github.com/xxx/config-repo
2.加載本地開發(fā)環(huán)境
spring.profiles.active=native spring.cloud.config.server.native.searchLocations=classpath:/config
3.加載 本地物理環(huán)境
spring.profiles.active=native spring.cloud.config.server.native.searchLocations= file:E:\\Java\\config
4.加載svn環(huán)境
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 環(huán)境 需要 引入 SVN jar包
<groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId>
springcloud統(tǒng)一配置中心(config server 端)
1.為什么要使用統(tǒng)一配置中心?
1.配置不方便維護
2.配置內(nèi)容的安全性和權(quán)限
3.更新配置項目需要重啟
2.登陸github 創(chuàng)建一個用于存放配置的項目


3.存放配置的項目的git地址 配置到項目的yml中
4.項目中的配置(Spring Cloud Config server 端)
該項目即是eureka的客戶端 又是Config的服務(wù)端
<?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上創(chuàng)建文件夾 用來存放配置信息

一般存三份
dev:開發(fā)test:測試pro:生產(chǎn)

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路徑 把拉下來的配置文件存在這
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java實現(xiàn)動態(tài)獲取圖片驗證碼的示例代碼
這篇文章主要介紹了Java實現(xiàn)動態(tài)獲取圖片驗證碼的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-08-08
詳細總結(jié)Java創(chuàng)建文件夾的方法及優(yōu)缺點
很多小伙伴都不知道如何用Java創(chuàng)建文件夾,今天給大家整理了這篇文章,文中有非常詳細的方法介紹及方法的優(yōu)缺點,對正在學習java的小伙伴們有很好地幫助,需要的朋友可以參考下2021-05-05
SpringBoot整合Redis并且用Redis實現(xiàn)限流的方法 附Redis解壓包
這篇文章主要介紹了SpringBoot整合Redis并且用Redis實現(xiàn)限流的方法 附Redis解壓包,本文給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧2024-06-06

