我在为Spring Cloud Config Server定义多个基于svn的配置存储库时遇到问题 . 我已经设置了三个配置存储库 . 一个用于开发,单元和 生产环境 . 我已将默认设置为开发(通过设置spring.cloud.config.server.svn.uri = development repo uri) . 但是,每当我向Config Server的REST endpoints 发出GET请求时,无论我请求哪个配置文件,我都会得到开发配置 . 见下面的例子......
ex:
curl -i -X GET \
-H "Content-Type:application/json" \
'http://localhost:8888/my-service-accounts/unit'
导致:
{
"name":"my-service-accounts",
"profiles":[
"unit"
],
"label":null,
"version":"750",
"propertySources":[
{
"name":"http://PATH_TO_MY_SVN_SERVER/config-repo-development/trunk/my-service-accounts.yml",
"source":{
"server.port":8080,
"hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds":3000
}
}
]
}
但我期待......
{
"name":"my-service-accounts",
"profiles":[
"unit"
],
"label":null,
"version":"750",
"propertySources":[
{
"name":"http://PATH_TO_MY_SVN_SERVER/config-repo-unit/trunk/my-service-accounts.yml",
"source":{
"server.port":7777,
"hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds":3000
}
}
]
}
- 注意propertySources [0] .name值的区别 . 我希望这个配置来自单元存储库,但它仍然来自开发存储库 .
我的配置服务器配置:
application.yml
server:
port: 8888
spring:
profiles:
include: subversion
cloud:
config:
server:
svn:
username: configserver
password: ************
uri: http://PATH_TO_MY_SVN_SERVER/config-repo-development
repos:
development:
pattern: ["*/development"]
uri: http://PATH_TO_MY_SVN_SERVER/config-repo-development
unit:
pattern: ["*/unit"]
uri: http://PATH_TO_MY_SVN_SERVER/config-repo-unit
production:
pattern:
- '*/production'
uri: http://PATH_TO_MY_SVN_SERVER/config-repo-production
discovery:
enabled: true
application:
name: my-server-config
- Note: my IDE (IntelliJ) is warning me that it cannot resolve the configuration property for spring.cloud.config.server.svn.repos.*.uri ... but this is how the Spring Cloud Config documentation shows how to specify the repository path.
build.gradle
buildscript {
ext {
springBootVersion = "1.3.3.RELEASE"
}
repositories {
mavenCentral()
maven {url "https://plugins.gradle.org/m2/"}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.5.RELEASE")
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.1.1"
}
}
apply plugin: "base"
apply plugin: "maven"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
jar {
baseName = project.ext.projectName
version = project.ext.projectVersion
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RC1"
}
}
dependencies {
compile("org.springframework.cloud:spring-cloud-starter-config")
compile("org.springframework.cloud:spring-cloud-config-server")
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compile("org.tmatesoft.svnkit:svnkit")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
eclipse {
classpath {
containers.remove("org.eclipse.jdt.launching.JRE_CONTAINER")
containers "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
}
}
task wrapper(type: Wrapper) {
gradleVersion = "2.12"
}
2 回答
我最终重新组织了我的svn配置库的目录布局,并使用更灵活的“searchPaths”属性来实现我所需的功能 .
新SVN回购布局:
/svn/config/trunk/dev/service-name.yml
/svn/config/trunk/prod/service-name.yml
/svn/config/trunk/unit/service-name.yml
基本上使用此方法,您可以定义配置存储库URI,然后定义searchPaths属性,该属性在传入路径上执行模式匹配,以确定要搜索配置的目录 .
新的application.yml
通过HTTP endpoints 访问配置服务器:
默认情况下,配置服务器似乎匹配
在我的情况下是:
为了清楚起见 . 我检查了代码,可以看到他们不支持多个SVN存储库实现 . 它仅适用于GIT .
在AbstractScmEnvironmentRepository中,他们有2个实施JGitEnvironmentRepository和SvnKitEnvironmentRepository . 现在,如果你检查谁扩展了这个JGitEnvironmentRepository,你会看到它有2个实现MultipleJGitEnvironmentRepository和PatternMatchingJGitEnvironmentRepository . 但是没有针对SVN存储库的Multi **实现 .