I. Overview
See Address: Https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_environment_repository
For example: git, svn, git-based local storage, local storage, Vault
Second, git
The default implementation of Environmentrepository uses the Git backend. To change the location of the repository, you can set the "Spring.cloud.config.server.git.uri" configuration property (for example, in application.yml) in the configuration server.
Benefits: Version auditing, distributed simplicity
Prepare for Work 1, create a new two git:
Sample:https://github.com/bjlhx15/spring-cloud-config-test-sample.git
Special:https://github.com/bjlhx15/spring-cloud-config-test-special.git
2. Clone to Local
Add APPLICATION.YML to each warehouse with the following content:
Configuration in Sample:
Profile:sample
Configuration in Special:
Profile:special
Then commit git.
2.1, Git URI placeholder 2.1.1, development
Code: Https://github.com/bjlhx15/spring-cloud/tree/master/config-part/microservice-config-server
Modify the configuration file: "Note the wildcard character {application}" in the URI
Server: 8080 Spring: Cloud: config: server: git: uri:https://github.com/bjlhx15/ {Application}
2.1.1, visit
Http://localhost:8080/spring-cloud-config-test-sample-default.yml
Http://localhost:8080/spring-cloud-config-test-special-default.yml
It can be found that different microservices correspond to different git configuration services and configure isolation.
2.2. Pattern matching and multiple repositories
There is also support for more complex requirements for pattern matching of application and configuration file names. The pattern format is a comma-separated list of {application}/{profile} names with wildcards (which may need to refer to a pattern that begins with a wildcard character). Cases:
Add development "SPRING-CLOUD-CONFIG-TEST-SPECIAL-DEV.YML" and test Environment "SPRING-CLOUD-CONFIG-TEST-SPECIAL-TEST.YML" to the special of the preparation work
The contents were as follows:
Spring-cloud-config-test-special-dev.yml
Profile:special-dev
Spring-cloud-config-test-special-test.yml
Profile:special-test
2.2.1, development
Code: Https://github.com/bjlhx15/spring-cloud/tree/master/config-part/microservice-config-server
To modify a configuration file:
Server: 8080 Spring: Cloud: config: server: git: uri:https://github.com/bjlhx15/ Spring-cloud-config-test-repo #公用的 repos: Simple:https:// github.com/bjlhx15/spring-cloud-config-test-sample Special: Special*/dev *,*special*/test* Uri:https://github.com/bjlhx15/ Spring-cloud-config-test-special
Actual test error, troubleshooting in progress
Binding to target org.springframework.cloud.config.server.ssh.SshUriProperties (uri=https://github.com/bjlhx15/ Spring-cloud-config-test-repo Hostkeyalgorithm=null, Hostkey=null, Privatekey=null, IgnoreLocalSshSettings=false, Knownhostsfile=null, Preferredauthentications=null, Stricthostkeychecking=true,) {repos={special= Org.springframework.cloud.config.server.ssh.SshUriProperties (uri=https://github.com/bjlhx15/ Spring-cloud-config-test-special Hostkeyalgorithm=null, Hostkey=null, Privatekey=null, ignoreLocalSshSettings= False, Knownhostsfile=null, Preferredauthentications=null, Stricthostkeychecking=true,)}} Failed:property: Spring.cloud.config.server.git.repos[sample] Value:https://github.com/bjlhx15/spring-cloud-config-test-sample Reason:failed to convert property value of type ' java.lang.String ' to required type ' Org.springframework.cloud.config.ser Ver.ssh.sshuriproperties$sshurinestedrepoproperties ' for property ' repos[sample] '; Nested exception is JAVA.LANG.ILLEGALSTATEEXCEption:cannot convert value of type ' java.lang.String ' to required type ' Org.springframework.cloud.config.server.ssh.sshuriproperties$sshurinestedrepoproperties ' for property ' repos[ Sample] ': No matching editors or conversion strategy found
Can view: org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository, repos properties
Enter ORG.SPRINGFRAMEWORK.CLOUD.CONFIG.SERVER.ENVIRONMENT.MULTIPLEJGITENVIRONMENTREPOSITORY.PATTERNMATCHINGJGITENVIRONMENTREP Ository: View to pattern and URI
The Pattern property in repo is actually an array, so you can use a YAML array (or suffixes such as [0],[1]) in a property file to bind to multiple schemas. You may need to do this if you want to run the application using multiple profiles.
Spring: Cloud: config: server: git: uri:https://github.com/spring-cloud-samples/ Config-repo Repos: Development: pattern: -' */development ' -' */staging ' uri:https:// Github.com/development/config-repo Staging: pattern: -' */qa ' -' */production ' URI: Https://github.com/staging/config-repo
2.3.searchpaths
Each repository can also choose to store the configuration files in subdirectories, and you can specify the mode in which these directories are searched as searchpaths. For example at the top level:
Server: port:8080spring: cloud: config: server: git: uri:https://github.com/bjlhx15/ Spring-cloud-config-test-repo searchpaths: -Foo # foo path -Bar # Bar Path
Access:
Http://localhost:8080/foo-dev.yml
Http://localhost:8080/bar-dev.yml
Http://localhost:8080/de-dev.yml
The server searches for configuration files in the top "/" and Foo subdirectories, and any subdirectories whose names begin with "bar". Make management a little clearer
In fact, you can also use a wildcard character
Spring: Cloud: config: server: git: uri:https://github.com/spring-cloud-samples/ Config-repo searchpaths: ' {application} '
2.4.Cloneonstart
The above code shows that the configuration is loaded when the call is used
Adding Property source:file:/c:/users/admini~1/appdata/local/temp/config-repo-6862549358101599484/ Application.yml
Add parameter
Spring: Cloud: config: server: git: uri:https://git/common/config-repo.git Cloneonstart:true #全部启动时候加载 repos: team-a: pattern:team-a-* cloneonstart:true URI: Http://git/team-a/config-repo.git team-b: pattern:team-b-* cloneonstart:false uri:http:// Git/team-b/config-repo.git team-c: pattern:team-c-* uri:http://git/team-a/config-repo.git
Third, user authorization
Configure user name password, etc.
Server: port:8080spring: cloud: config: server: git: uri:https://github.com/ Bjlhx15/spring-cloud-config-test-repo Username: * * * Password: * *
0702-spring Cloud Config-git Warehouse configuration, user authorization