一、配置中心配置
1.ConfigApplication配置中心添加注解@EnableDiscoveryClient、@EnableConfigServer
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
2.配置远程端git或svn路径或本地路径
配置远程端git或svn路径
spring:
application:
name: config
cloud:
config:
server:
git:
uri: https://gitee.com/matea/config-repo
username: 13985138082
password: zxcvbnm1
basedir: E:\WorkSpace\IDEA\config-git
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
配置本地路径
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/config
basedir:指定配置文件下载存放路径
二、调用配置中心配置
1.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2.添加参数配置name、profile
spring:
application:
name: order
cloud:
config:
discovery:
enabled: true
service-id: CONFIG
profile: dev
调用配置中心CONFIG中的order-dev.yml配置文件
3.使用启动引导配置文件,优先启动
- application.yml 改名为bootstrap.yml
三、注意:
- 如果你配置的是order-dev.yml来读取,实际上order.yml也会读取,系统会两个合并后读取合并的配置文件