config使用本地文件系统的存储方式来保存配置信息

1.搭建Config Server

  <1>pom.xml中引入依赖

  <2>编写配置文件application.yml

  <3>在src/main/resources创建配置文件

  <4>在启动类上增加注解@EnableConfigServer

  <5>启动工程,测试应用

2.搭建Config Client

  <1>pom.xml中引入依赖

  <2>编写配置文件bootstrap.yml

  <3>在启动类上增加注解@RestController

  <4>启动工程测试应用

详细:

1.搭建Config Server

  <1>pom.xml中引入依赖

<dependencies>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-config-server</artifactId>
      </dependency>
 </dependencies>

  <2>编写配置文件application.yml

spring:
  application:
    name:
      config
  profiles:
    active: native    #使用本地文件系统的存储方式来保存配置信息
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/shared
server:
  port:
    8888

  <3>在src/main/resources/shared创建配置文件(新建shared目录)

application-order.yml

clientParam:
  native-order-1.0
eureka:
  instance:
    prefe-ip-address:true   #是否显示主机的IP
  client:
    registerWithEureka: true
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://localhost:8762/eureka/ #指定Eureka服务端地址
spring:
  application:
    name:
      order  #模块的名称
server:
  port:
    7000  #指定该Eureka实例的端口号

  <4>在启动类上增加注解@EnableConfigServer

  <5>启动工程,测试应用

http:localhost:8888/config/order

2.搭建Config Client

  <1>pom.xml中引入依赖

 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

  <2>编写配置文件bootstrap.yml

spring:
  application:
    name:
      order
  cloud:
    config:
      profile:
        order
      uri:
        http://localhost:8888/   #配置中心
server:
  port:7000

  <3>启动工程测试应用

成功!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值