Spring Cloud Config git版

由于在学习这块内容的时候还不会使用gitHub所以就用了osc的码云

config server

POM文件

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-config-server</artifactId>
</dependency>

git版配置文件

spring:
application:
  name: config-server
cloud:
  config:
    server:
      git:
        uri: https://gitee.com/qubaba/spring-cloud-config # git路径
        username: # 私有仓库的话需要输入git的账号密码
        password:
        search-paths: /spring-cloud-config # 查找该路径下的所有文件
        default-label: spring-cloud-config # 默认的分支

启动类

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

}

关键注解为:@EnableConfigServer表示启动类为配置服务类。

 

访问到配置服务器的配置文件后会在本地生成一份配置文件的副本。

config Client

POM文件

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

配置文件

spring cloud config 的配置文件需要提前加载所以需要在resources目录下新建文件bootstrap.yml文件

spring:
profiles:
  active: dev # 默认加载配置文件
application:
  name: config
cloud:
  config:
    uri: http://localhost:9000 # 配置服务器地址
    name: ${spring.application.name} # application Name
    profile: ${spring.profiles.active} # 那个类型的配置为文件

猜你喜欢

转载自www.cnblogs.com/qubaba/p/10843201.html