Spring Cloud iToken实战项目(九):重构改善既有代码的设计

本文介绍如何使用 Spring Cloud Config 实现配置中心,并详细展示了创建配置项目、配置文件管理和跨项目配置同步的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现 Spring Cloud Config Client 通用配置

创建itoken-config-respon项目

复制itoken-config项目下的respon文件夹到当前项目,防止配置文件更新触发itoken-config自动部署
在这里插入图片描述

新建公共配置文件

新建itoken-common-service-dev.ymlitoken-common-service-prod.yml,提取各自的公有配置
itoken-common-service-prod.yml

spring:
  boot:
    admin:
      client:
        url: http://192.168.206:8084
  zipkin:
    base-url: http://192.168.206:9411
mybatis:
    type-aliases-package: com.funtl.itoken.common.domain.entity
    mapper-locations: classpath:mapper/*.xml
eureka:
  client:
    serviceUrl:
      defaultZone: http://192.168.206.132:8761/eureka/,http://192.168.206.132:8861/eureka/
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: health,info

删除其他配置文件的公有配置

itoken-service-admin-prod.yml 删除公有配置

spring:
  application:
    name: itoken-service-admin
  datasource:
    druid:
      url: jdbc:mysql://106.12.8.40:3306/itoken-service-admin?useUnicode=true&characterEncoding=utf-8&useSSL=false
      username: root
      password: lusifer357159
      initial-size: 1
      min-idle: 1
      max-active: 20
      test-on-borrow: true
      # MySQL 8.x: com.mysql.cj.jdbc.Driver
      driver-class-name: com.mysql.jdbc.Driver

server:
  port: 8501

修改每个项目下的bootstrap配置文件, 新增itoken-common-service公用配置

spring:
  cloud:
    config:
      uri: http://192.168.206.132:8888
      name: itoken-common-service, itoken-service-admin
      label: master
      profile: prod
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值