auto-config.xml 与 antx.properties

xiaoxiao2021-02-28  19

自动加载配置文件


描述

开发环境修改配置文件 auto-config.xml application.properties.vm 文件,代码合并至测试环境 服务部署时,执行./builde.sh ;部署过程中,提示是否更新 antx.properteis ,选择是,系统自动将本次 auto-config.xml 中新增内容同步到 antx.properties 中


原理

auto-config.xml 与 antx.properteis

若 auto-config.xml 有新增 key-value,则会同步到 antx.properties 中若 auto-config.xml 中更改 value 值 ,不会同步到 antx.properties 中若 antx.properties 中更改 value 值,不会被 auto-config.xml 中原有信息覆盖

application.properties.vm 中添加占位符与name值的对应关系

项目运行时,配置文件加载占位符的位置,通过 application.properties.vm 找到对应name值,name值与 auto-config.xml 对应

部署服务器中既有 auto-config.xml 又有 antx.propertis 为何要增加 antx.propertis ?

项目通过 git 管理,.gitignore 中配置 antx,properties ; antx.properties 不需要添加到 git 版本管理中 ;本地开发环境目录地址 {home}/antx.properties 有此文件maven 实现自动化配置工具,项目打包时不对 auto-config.xml 进行打包

实现

自动化配置工具pom.xml <plugin> <groupId>com.alibaba.citrus.tool</groupId> <artifactId>autoconfig-maven-plugin</artifactId> <version>1.2</version> <configuration> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>autoconfig</goal> </goals> </execution> </executions> </plugin>

参考资料

autoconfig.xml与antx.properties一级application.properties之间的关系Webx autoconfig 多环境封装 使用总结java自动化配置工具 - autoconfig 简介
转载请注明原文地址: https://www.6miu.com/read-2630489.html

最新回复(0)