demo
#环境名
spring.profiles=dev
server.port=8084
server.servlet.context-path=/
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
<!--springcloud分布式配置-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
// 记得加这个注解
@EnableConfigServer
#常规配置
server.port=3081
server.servlet.context-path=/
# 需要配置连接github/gitee
# 仓库地址
spring.cloud.config.server.git.uri=https://gitee.com/licha233/springcloud-config
# 账号
spring.cloud.config.server.git.username=1149196266@qq.com
# 密码
spring.cloud.config.server.git.password=123456
# 配置git仓库的搜索路径(这个配置是固定的)
spring.cloud.config.server.git.search-paths=config-repo
# 跳过安全认证
spring.cloud.config.server.git.skip-ssl-validation=true
之后client端如果要使用远程的服务器端加载配置文件,就必须用bootstrap.properties文件,不能再用application.properties , 因为这个文件只能从本地加载配置
bootstrap.properties demo
# 设置客户端所需要的配置文件的唯一标识
# 唯一标识的值一定要和文件名相同
spring.cloud.config.name=application-dev
# 再次去检测唯一标识是否正确
spring.cloud.config.profile=dev
# 设置label(默认是master)
spring.cloud.config.label=master
# 配置分布式配置中心的服务器地址
spring.cloud.config.uri=http://localhost:3081
1.通用型(无论配置文件是yml还是properties都好使)
/{application/properties}//
一个命名空间中可以存放多个仓库,作用就是实现分类存储!!
2.只能适用于properties
/-.properties
//-.properties(适用于自己指定了命名空间,没有用github默认的master)
3.只能适用于yml
/-.yml
//-.yml\
可以同时存在
优先级顺序 bootstrap.properties>application.properties
因为 bootstrap.properties 是系统所提供的配置
? application.properties是用户级别的配置
如果两个文件有重复的配置,优先级高的会覆盖优先级低的配置
原文:https://www.cnblogs.com/licha233/p/12847091.html