After completing the above verification, make sure that the Configuration service center is working, and below we try to get the configuration information described above in the MicroServices app.
- Create a spring boot application, named
config-client
, and introduce the pom.xml
following dependencies in:
12345678910 |
<dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-config</artifactid> </dependency> </dependencies> |
- Create a Spring boot application main class, as follows:
12345678 |
@SpringBootApplication public class application { public static void main(string[] args) { new Springapplicationbuilder (Application.class). Web (True). Run (args); } |
- Create
bootstrap.yml
a configuration to specify where to get the configuration file config-server-git
, for example:
1234567891011 |
Spring: Application: name:config-client Cloud: Config: uri:http://localhost:1201/ Profile:default Label:master Server: Port: 2001 |
The above configuration parameters correspond to the various parts of the configuration file stored in Git, as follows:
- Spring.application.name: Part of the corresponding profile rule
{application}
- Spring.cloud.config.profile: Part of the corresponding profile rule
{profile}
- Spring.cloud.config.label: Part of the corresponding profile rule
{label}
- Spring.cloud.config.uri:
config-server
Address of the configuration center
It is important to note that the above properties must be configured in bootstrap.properties so that the configuration information in the Config-server is loaded correctly.
After you have finished writing your code, the reader can start Config-server-git, config-client, and we can see that the endpoint will return the configuration information obtained from the GIT repository:
123 |
{"profile": "Default"} |
Alternatively, we can modify the Config-client profile to Dev to see the changes in the loading configuration.
From now on, I will record the process and the essence of the recently developed Springcloud micro-service cloud architecture, and help more friends who are interested in developing the Spring cloud framework, hoping to help more good scholars. Let's explore how the Spring cloud architecture is built and how it can be used in enterprise projects. SOURCE Source
Spring Cloud Build Client