config service 入门:
pom.xml 配置
<?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>
<groupId>com.silk-road</groupId>
<artifactId>silk-road-config</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>jar</packaging>
<name>silk-road-config</name>
<description>配置管理服务</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
</properties>
<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>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--config server need read svn-->
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
</dependency>
</dependencies>
</project>
config service 默认使用 git管理配置文件,如果使用svn需要在引入org.tmatesoft.svnkit 依赖
启动类 加@EnableConfigServer @SpringBootApplication 注解
application.yml 配置:
# http
server:
port: 8888
context-path: /silk-road-config
# spring cloud config
spring:
application:
name: silk-road-config
cloud:
config:
enabled: true
discovery:
enabled: true
server:
svn:
uri: svn://59.110.1.1/silk-road-properties/
username: 用户名
password: 密码
default-label: trunk
profiles:
active: subversion #使用git不用可以不用此配置,使用svn需要配置
- {application}(配置的应用名)映射到Config客户端的spring.application.name属性
- {profile}(环境名)映射到Config客户端的spring.profiles.active属性,可以用来区分环境
- {label}(分支名)映射到Git服务器的commit id, 分支名称或者tag,默认值为master;svn默认值为trunk
验证config service
http请求地址和资源文件映射如下:
- /{application}/{profile}[/{label}]
- /{application}-{profile}.yml
- /{label}/{application}-{profile}.yml
- /{application}-{profile}.properties
- /{label}/{application}-{profile}.properties
浏览器出现此数据说明config server搭建成功
客户端配置
pom.xml