1.统一配置中心config
1.config-server 导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2.config-server 主类上加注解 @EnableConfigServer
3.配置yml文件
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/songqq123/config-repo
username: 431901509@qq.com
password: song1003
basedir: D:\config2
4.config-client导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
5.配置bootstrap.yml文件
spring:
application:
name: product
cloud:
config:
discovery:
enabled: true
service-id: config
profile: dev
eureka:
client:
service-url:
defaultZone: http://localhost:8762/eureka/
6.补充知识:
/{name}-{profiles}.yml
/{label}/{name}-{profiles}.yml
name 服务名
profiles 环境
label 分支
本文详细介绍了如何使用Spring Cloud Config实现统一配置管理。包括config-server和config-client的搭建,通过Git存储配置,以及如何在微服务中应用这些配置。适用于希望了解Spring Cloud配置中心具体实践的开发者。
943

被折叠的 条评论
为什么被折叠?



