Spring Cloud Configprovides server and client support for external configurations in distributed systems. UseConfig Server, you can manage the external properties of your application in all environments. Conceptual mapping on the client and serverSpring Environmentand thePropertysourceabstract the same. Spring Cloud ConfigSupport inGit, SVNand local storage configuration files, using theGitorSVNRepositories are a good way to support versioning,SpringThe default configuration is to use theGitRepositories ,This makes it easy to support the configuration environment for the label version, as well as access to various tools for managing content.
7.1. Server-Side
new Spring boot project demo-springcloud-config-server, New start configserverapplication,@ Enableconfigserver turn on the configuration Center feature
Project Dependent spring-cloud-config-server support for configuration center
profile application.properties, the reader fills in its own GitHub account and password to access the configuration address https://github.com/yhqnh/ Spring-cloud-demo-config-server-git.git
Github Configuration Address https://github.com/yhqnh/spring-cloud-demo-config-server-git.git is public, and the project is created under the Config-repo Directory, created four configuration file project.properties,
Project-dev.properties,
project-test.properties,
Project-prod.properties
are configured separately
github=github-default-1.0,
github=github-dev-1.0,
github=github-test-1.0,
github=github-prod-1.0
The URL of the Spring cloud Config configuration information is mapped to the configuration file as follows:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
above theUrlwill map{application}-{profile}.propertiesthe corresponding configuration file, where{Label}correspondingGiton a different branch, the default isMaster. Launch app with browser accessHttp://localhost:5551/project/devwill bemapped intoproject-dev.propertiesin thisAccessDevconfiguration file
7.2. Client
Create a new spring boot project and name Demo-springcloud-config-client, creating a startup class Configclientapplication
configuration file bootstrap.properties, Multi-environment configuration spring.profiles.active=dev indicates activation dev configuration
local New configuration file application-dev.properties
New Yhqcontroller, get the configuration file we use two ways, a @Value, a environment
Critical dependencies
launch app browser access Http://localhost:5552/getConfigFromValue and the http://localhost:5552/getConfigFromEnviroment before reading Local configuration file variable value github-local-1.0
We do a validation by preceding the load order 7 prior to 8. Set the Spring.cloud.config.uri value of the bootstrap.properties to get the configuration from the configuration server built above
launch the App browser Http://localhost:5552/getConfigFromValue and the http://localhost:5552/getConfigFromEnviroment Get to the github-dev-1.0 and not github-local-1.0
below endpoints, adding dependencies Spring-boot-starter-actuator provide us with refresh endpoint / Refresh and modify Bootstrap.properties to close Springboot 1.5.X Above default security authentication access /refresh
yhqcontroller add refresh annotations @RefreshScope launch app access http://localhost:5552/getconfigfromvalue and http://localhost:5552/getconfigfromenviroment return results such as github-dev-1.0
At This point we modify the GitHub value on the Config Center Server to github-dev-1.0-modify
Visit Again Http://localhost:5552/getConfigFromValue and the http://localhost:5552/getConfigFromEnviroment return Results or is as github-dev-1.0
How to configure no dynamic refresh, this requires the post method to access the http://localhost:5552/refresh Endpoint
Visit Again Http://localhost:5552/getConfigFromValue and the http://localhost:5552/getConfigFromEnviroment See If the configuration is active
Dry Goods sharing microservices Spring-cloud (7. Configuration Center Spring-cloud-config)