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

不念不忘少年蓝@ 2023-05-29 11:40 61阅读 0赞

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

1.在pom.xml中增加依赖

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-config</artifactId>
  4. </dependency>

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

  1. spring:
  2. cloud:
  3. config:
  4. uri: http://localhost:8888
  5. name: web-admin-feign
  6. label: master
  7. profile: dev

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

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

  1. spring:
  2. application:
  3. name: hello-spring-cloud-web-admin-feign
  4. thymeleaf:
  5. cache: false
  6. mode: LEGACYHTML5
  7. encoding: UTF-8
  8. servlet:
  9. content-type: text/html
  10. server:
  11. port: 8766
  12. feign:
  13. hystrix:
  14. enabled: true
  15. eureka:
  16. client:
  17. serviceUrl:
  18. defaultZone: http://localhost:8761/eureka/

将配置文件上传到git

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

  1. spring:
  2. cloud:
  3. config:
  4. uri: http://localhost:8888
  5. name: web-admin-feign
  6. label: master
  7. profile: prod

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

发表评论

表情:
评论列表 (有 0 条评论,61人围观)

还没有评论,来说两句吧...

相关阅读