seagull7558
V2EX  ›  Java

Java 多模块项目如何封装统一的配置信息

  •  
  •   seagull7558 · Jul 14, 2022 · 1954 views
    This topic created in 1400 days ago, the information mentioned may be changed or developed.

    例如针对 mysql,建立一个客户端通用配置 mysql-conf 模块,定义一些 mysql 连接池和驱动配置

    其他业务模块依赖 mysql-conf 这个模块,并且定义数据库地址,账号密码

    这样业务模块就有统一的连接池配置和自定义的数据库连接配置了

    请问如何实现呢?

    7 replies    2022-07-15 09:18:59 +08:00
    LeegoYih
        1
    LeegoYih  
       Jul 14, 2022
    分布式配置中心
    sprit
        2
    sprit  
       Jul 14, 2022
    spring 的话可以做成 starter
    lllllliiii
        3
    lllllliiii  
       Jul 14, 2022
    思路出来了,代码其实也就出来了

    ---
    而你已经有思路了
    seagull7558
        4
    seagull7558  
    OP
       Jul 14, 2022
    好家伙 楼上三位谜语人是吧 doge&

    目前理解是 例如 nacos

    1.自定义配置类
    2.实现 PropertySourceLocator 并且执行顺序在 nacos 之前去修改配置文件配置项
    4. org.springframework.cloud.bootstrap.BootstrapConfiguration 完成装配
    kytrun
        5
    kytrun  
       Jul 14, 2022 via Android
    子模块的 yml 配置文件可以被包含,好像是 profiles.include
    micean
        6
    micean  
       Jul 14, 2022
    最简单就是楼上的 spring.profiles.include ,业务模块依赖配置文件所在模块就可以了
    nothingistrue
        7
    nothingistrue  
       Jul 15, 2022
    对于你的标题:Spring Cloud Config 。

    对于你的内容,跨服务不要共享一个数据库,服务内跨模块不要分离人工配置(默认配置可以分离)。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   999 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
    ♥ Do have faith in what you're doing.