Spring cloud -- config configuration center

Keywords: Programming git Spring Eclipse github

Config Server configuration

It provides centralized external configuration for microservices, and configuration server provides centralized external configuration for various environments of each microservice application.

Configuration information and business code are managed separately to support dynamic configuration of multiple environments.

Integrated config server

1 pom add dependency

<!-- springCloud Config -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-config-server</artifactId>
		</dependency>
		<!-- avoid Config Of Git Plug in error: org/eclipse/jgit/api/TransportConfigCallback -->
		<dependency>
			<groupId>org.eclipse.jgit</groupId>
			<artifactId>org.eclipse.jgit</artifactId>
			<version>4.10.0.201712302008-r</version>
		</dependency>

2 application.yml configuration modification

server: 
  port: 3344 
  
spring:
  application:
    name:  microservicecloud-config
  cloud:
    config:
      server:
        git:
          uri: git@github.com:zzyybs/microservicecloud-config.git #git configuration warehouse name

3. Add startup configuration to startup class

@SpringBootApplication
@EnableConfigServer
public class ConfigSpringCloudApp
{
	public static void main(String[] args)
	{
		SpringApplication.run(ConfigSpringCloudApp.class, args);
	}
}

4 access the configuration address to get the configuration file information of remote git

5. Client project obtains configuration information through config server

5.1 add dependency to POM file

<!-- SpringCloud Config Client -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>

5.2 add bootstrap.yml to obtain resource configuration information

spring:
  cloud:
    config:
      name: microservicecloud-config-client #The resource name that needs to be read from github, note that there is no yml suffix
      profile: test   #Configuration items accessed this time
      label: master   
      uri: http://config-3344.com:3344 ා after starting the microservice, go to the 3344 service first, and get the service address of GitHub through SpringCloudConfig

Posted by EWaveDev on Thu, 13 Feb 2020 07:21:58 -0800