官方链接与文档 写道
https://spring.io/guides/gs/centralized-configuration/
Spring cloud config Server基于Spring boot构建,
- 建议下载使用官方的Eclipse ( sts-3.7.2.RELEASE)
- 下载config server sample 的源码,并导入到eclipse工程中,gs-centralized-configuration-complete\configuration-service
- 修改配置文件
- 启动程序
配置文件 maven文件:
4.0.0 com.example configuration-service 0.0.1-SNAPSHOT jar org.springframework.boot spring-boot-starter-parent 1.2.8.RELEASE UTF-8 1.8 org.springframework.cloud spring-cloud-config-server org.springframework.boot spring-boot-starter-test test org.tmatesoft.svnkit svnkit org.springframework.cloud spring-cloud-starter-parent Angel.SR4 pom import org.springframework.boot spring-boot-maven-plugin
application.properties:
server.port=8888 spring.application.name=configServer #spring.cloud.config.server.git.uri=${HOME}/Desktop/config spring.profiles.active=subversion spring.cloud.config.server.svn.uri=svn://IP:port/project/config spring.cloud.config.server.svn.username=lvdccyb spring.cloud.config.enabled=true [email protected] spring.main.show-banner=false
其中这3项表面使用svn,并需要注意,远程url可用。
spring.profiles.active=subversion spring.cloud.config.server.svn.uri=svn://IP:port/project/config spring.cloud.config.server.svn.username=lvdccyb
运行结果(部分内容去掉):
http://localhost:8888/env
{
"profiles": [
"subversion"
],
"bootstrap": {},
"servletContextInitParams": {},
"configServerClient": {
"spring.cloud.config.enabled": "false"
},
"applicationConfig: [classpath:/application.properties]": {
"spring.cloud.config.server.svn.password": "******",
"spring.cloud.config.server.svn.uri": "svn://X.Y.Z.U/project/config",
"server.port": "8888",
"spring.profiles.active": "subversion",
"spring.main.show-banner": "false",
"spring.cloud.config.enabled": "true",
"spring.cloud.config.server.svn.username": "lvdccyb",
"spring.application.name": "configServer"
},
"defaultProperties": {
"spring.application.name": "bootstrap"
}
}
http://localhost:8888/configuration-client/default 注意上面地址:对应的svn地址一般为: svn://IP:PORT/{$配置的uri}/trunk/configuration-client.properties 而且这个地址,需要仔细阅读spring 官方文档对application,profile,label的解释,以及路径的寻找优先级,上述地址缺省配置时,可以写成多种多样: http://localhost:8888/configuration-client/default/trunk http://localhost:8888/configuration-client/trunk/trunk http://localhost:8888/configuration-client/trunk 甚至如下: http://localhost:8888/configuration-client/abc 这里需要多一级trunk目录,而不是直接使用配置文件。 { "name": "configuration-client", "profiles": [ "default" ], "label": "trunk", "propertySources": [ { "name": "svn://IP:PORT/{$配置的uri}/trunk/configuration-client.properties", "source": { "IamApplicationName": "true", "message": "Hello World,I am spring client" } } ] }