欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(11)springcloud配置中心--客户端

程序员文章站 2024-03-20 22:41:10
...

以hello-spring-cloud-web-admin-feign为例,

1.在pom.xml中增加依赖

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

2.在application.yml原来配置删掉,加如下配置,

spring:
  cloud:
    config:
      uri: http://localhost:8888
      name: web-admin-feign
      label: master
      profile: dev

3.启动WebAdminFeignApplication项目,在启动日志中可以看到 端口号是8765

4.在hello-spring-cloud新建web-admin-feign-prod.yml

spring:
  application:
    name: hello-spring-cloud-web-admin-feign
  thymeleaf:
    cache: false
    mode: LEGACYHTML5
    encoding: UTF-8
    servlet:
      content-type: text/html

server:
  port: 8766

feign:
  hystrix:
    enabled: true

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

将配置文件上传到git

5.将第2步的application.yml配置文件中的profile:dev改成 profile:prod

spring:
  cloud:
    config:
      uri: http://localhost:8888
      name: web-admin-feign
      label: master
      profile: prod

再次启动WebAdminFeignApplication项目,在启动日志中可以看到 端口号是8766

相关标签: springcloud config