011 统一配置中心

一、配置中心配置

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也会读取,系统会两个合并后读取合并的配置文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值