1. Project environment
SpringBoot 2.1.7.RELEASE and SpringCloud Greenwich.SR2 are used in the project:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2.Config-Server first ensure that it is started normally, and check whether the configuration file on github is correct;
For example: if the configuration content format is incorrect, access here will report an error;
3. Question:
config-client has been unable to obtain the attribute value of the config-server configuration file on github;
(1). Bootstrap configuration read priority over application
General application.yml /application.properties Modified bootstrap.yml /bootstrap.properties
(2) Configuration file format on github: (Note: It is easy to encounter pits)
/{application}/{profile}[/{label}]:
1: /{application}-{profile}.yml
2: /{label}/{application}-{profile}.yml
3: /{application}-{profile}.properties
4: /{label}/{application}-{profile}.properties
(3) The wrong configuration file I just started:
Error one:
1: config-client 中 的 bootstrap.yml :
spring:
cloud:
config:
uri: http://localhost:8765
profile: dev
2:github:
ps: At first I thought that as long as the following dev is consistent with spring.cloud.config.profile = dev, it turns out that it is not possible;
Error two:
1: config-client 中 的 bootstrap.yml :
spring:
cloud:
config:
uri: http://localhost:8765
profile: dev
At first, I thought that the following service name configuration was placed on github, and then read it with config-client, so I just changed the configuration file name format on github to the following, and found that it was still not possible
spring:
application:
name: morning-service-order
github: The configuration file is modified as follows: (Attach: yml online to properties )
correct:
My approach is to configure the service name in bootstrap.yml and name the configuration file in github:
Or yml format: