首页 > 学院 > 开发设计 > 正文

profile分环境配置流程

2019-11-11 01:37:51
字体:
来源:转载
供稿:网友

一. 背景

为解决资源文件中配置参数不一致导致的git分枝不统一问题(如qa环境定制化配置),减少代码合并复杂度,降低出错概率,故使用PRofile进行分环境配置。

二. 操作流程

分环境目录创建

根据不同环境新建不同的目录resources.local、resources.prod,并将文件及目录拷贝到相应目录下,并根据环境修改相应的配置,详细如下

2. pom.xml修改

a. 配置profiles

每个profile为一个环境配置,其中参数包括

id:环境的唯一标识

properties: 环境属性,可用于后续提供编译参数

activation:true默认参数启动环境

  相关核心片段如下:

<profiles>
    <!-- 测试环境 -->    <profile>        <id>dev</id>        <properties>            <env_config>local</env_config>        </properties>        <distributionManagement>            <repository>                <id>central</id>                <name>local and develop environment private nexus test snapshots</name>                <url>http://。。。</url>            </repository>            <snapshotRepository>                <id>snapshots</id>                <name>local private nexus test snapshots</name>                <url>http://。。。</url>            </snapshotRepository>        </distributionManagement>    </profile>       <!--QA 环境-->    <profile>        <id>qa</id>        <properties>            <env_config>local</env_config>        </properties>        <activation>            <activeByDefault>true</activeByDefault>        </activation>        <distributionManagement>            <repository>                <id>central</id>                <name>qa environment private nexus releases</name>                <url>http://...</url>            </repository>            <snapshotRepository>                <id>snapshots</id>                <name>qa environment private nexus snapshots</name>                <url>http://...</url>            </snapshotRepository>        </distributionManagement>    </profile>    <!-- 生产环境 -->    <profile>        <id>prod</id>        <properties>            <env_config>prod</env_config>        </properties>        <distributionManagement>            <repository>                <id>**-nexus-releases</id>                <name>prod environment private nexus releases</name>                <url>http://...</url>            </repository>            <snapshotRepository>                <id>**-nexus-snapshots</id>                <name>prod environment private nexus snapshots</name>                <url>http://...</url>            </snapshotRepository>        </distributionManagement>    </profile></profiles>

b. <build>配置

此部分是配置打包的资源文件,其资源调用参数由profile的属性env_config提供,具体如下:

<build>    <resources>        <resource>            <directory>${project.basedir}/src/main/resources</directory>        </resource>        <resource>            <directory>src/main/resources.${env_config}</directory>        </resource>    </resources></build>

3. jar包部署命令

mvn -Pid clean deploy,其中id为profile中的实际id值


上一篇:HashTable

下一篇:Leetcode: Combination Sum III

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表