config组件与bus组件
config组件-配置文件统一管理和动态刷新
config服务端搭建
- 引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
- 加入启动类注解@EnableConfigServer
package com.illriver.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
- 配置文件增加远程配置仓库地址
server:
port: 31007
spring:
application:
name: illriver-bbs-config
cloud:
config:
server:
git:
uri: https://gitee.com/illriver/config.git
basedir: D:\software\IntelliJ Project\config\src\main\resources\localconfig #本地仓库路径
default-label: master #默认远程分支
注意事项:
- 远程配置文件按照client-[指定环境].yml、client.yml顺序读取
- 指定本地配置仓库一定要是空目录
- 私有仓库需要指定github、gitlab、等用户名密码
查看配置文件接口:
http://{config-server-host}:{port}/{client}-{env}.yml
指定分支客户端配置查询接口:
http://{config-server-host}:{port}/{client}/{label}
config服务端搭建
- 引入依赖(同样需要consul及健康检查依赖,这里就展示了)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
- 增加配置文件(修改配置文件为bootstrap.yml则先读取配置仓库中配置)
spring:
cloud:
config:
discovery:
enabled: true
service-id: illriver-bbs-config
label: master
name: goods
profile: dev
手动刷新配置文件
-
配置端点暴露
![]()
-
使用POST请求手动刷新接口:
http://{config-server-client}:{port}/actuator/refresh


浙公网安备 33010602011771号