springcloud 分布式配置中心(spring cloud config)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32534855/article/details/84433022

官方中文文档:https://springcloud.cc/spring-cloud-config.html

条件:每次修改配置,都需要去找相应的配置文件,造成了不必要的开销,现在我们可以在远端Git上修改,然后修改相应的服务

1.现在码云上创建一个私有项目config-repo

2.创建config项目

2.1pom文件

		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-config-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>

因为config也是一个服务,需要注册到Eureka上面

2.2启动类

@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigApplication.class, args);
	}
}

2.3application.yml配置文件

eureka:
  client:
    service-url:
      defaultZone:  http://localhost:8761/eureka/
spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/DencyCheng/config-repo
          username: DencyCheng
          password: xxxxx #改成自己的密码
          basedir: D:\ideawork\springcloud_sell\baseDir #从远端Git缓存下来的配置文件下载地址

3.测试

3.1远端GIt配置文件

3.2启动Eureka,启动三个config实例

3.3访问

上面可以看见,配置文件跟Git上面的一样

猜你喜欢

转载自blog.csdn.net/qq_32534855/article/details/84433022