1.配置中心
1.pom添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2.启动添加注解
@EnableConfigServer
3.application添加
spring
cloud:
config:
server:
git:
uri: http://git.oschina.net/didispace/config-repo-demo/
skip-ssl-validation: true
2.客户端
1.pom添加依赖
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.启动类添加注解
@RefreshScope
3.bootstrap添加
spring:
cloud:
config:
fail-fast: true
label: master
discovery:
enabled: true
service-id: 配置中心的application.name
name: Git仓库的文件名
profile: dev/pord自定义
4.当Git配置文件有修改时,需要动态刷新
POST访问客户端地址 + /actuator/refresh