Create the configuration center server
Add a profile contents created project
server.port=9004
spring.application.name=spring-cloud-config-server-01
#git仓库地址
spring.cloud.config.server.git.uri=http://git.home/test/config-depot.git
#仓库内的相对路径
spring.cloud.config.server.git.search-paths=/config
#git用户名
spring.cloud.config.server.git.username=sunweisheng
#git密码
spring.cloud.config.server.git.password=********
Add annotations to open a distribution center (SpringCloudConfigServerApplication.java)
@SpringBootApplication
//启动配置中心
@EnableConfigServer
public class SpringCloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudConfigServerApplication.class, args);
}
}
Add a profile in the git warehouse
Git repository Name: config-depot, warehouse created under the root of config folder, create a profile ConfigDepot-Test.properties in the config directory, configuration file contents: bluersw.config = Test-1
Test Configuration Center
Access in the browser 127.0.0.1:9004/ConfigDepot/Test, returns the contents of the configuration file Json format, proof read Git repository content distribution center success.
{
"name":"ConfigDepot",
"profiles":["Test"],
"label":null,
"version":"e3fdd0937bba0ad2df3eefe09ac3ab33ca09397b",
"state":null,
"propertySources":[{
"name":"http://git.home/test/config-depot.git/config/ConfigDepot-Test.properties",
"source":{
"bluersw.config":"Test-1"
}
}]
}
Warehouse configuration file path can be transformed into a REST interface to access the configuration center, the conversion rules:
- /{application}/{profile}[/{label}]
- /{application}-{profile}.yml
- /{label}/{application}-{profile}.yml
- /{application}-{profile}.properties
- /{label}/{application}-{profile}.properties
PS: Configuration Center to read Git repository information is not cached, if the contents of the configuration file is changed Test-3, refresh the page, you can see the direct value (Test-3) has just changed.
Source
Github repository: https: //github.com/sunweisheng/spring-cloud-example