• maven pom文件通过profile配置多环境开发学习


    目前主流的springboot项目设置了提供了springboot spring.profiles.active支持多环境下,几套配置文件切换。用起来已经非常方便

    在这里插入图片描述

    在传统的springmvc项目没使用pom profile时,我是在spring application.xml加载properties时选择加载哪个配置文件。这样切换频繁的修改spring application.xml文件也能实现。

    在这里插入图片描述
    这种方式在项目打包后xml文件是和源码一样的,在项目启动时,spring加载对应的配置文件填充 ${}属性
    在这里插入图片描述

    maven也提供了 pom文件通过profile配置多环境开发,下面学习下该方式

    首先提下这种方式和sping加载配置文件的区别,pom文件通过profile配置的方式xml编译后里面的${}属性都是被替换掉实际的值了,不需要通过spring加载propertios来填充了。

    1 新建2个properties

    在这里插入图片描述

    2 pom.xml新增标签配置profile

    <profiles>
            <profile>
                <id>releaseid>
                <activation>
                    <activeByDefault>trueactiveByDefault>
                activation>
                <build>
                    <filters>
                        <filter>src/main/resources/profileconfig/cytjws-release.propertiesfilter>
                    filters>
                build>
                <properties>
                    <exclude.logfile>exclude.logfile>
                properties>
            profile>
            <profile>
                <id>devid>
                <build>
                    <filters>
                        <filter>src/main/resources/profileconfig/cytjws-dev.propertiesfilter>
                    filters>
                build>
            profile>
        profiles>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    加完 reload maven 工程后 Profiles下面及多出了 dev,和release2个选项,根据activeByDefault配置,默认是relesae打勾的
    在这里插入图片描述

    3 pom文件增加 标签

    标签是在 标签下的,通过标签指定web项目打包到classes下的资源,maven项目默认就是src/main/java,src/main/resources,配置文件按规范都是放到src/main/resources下。
    所以在src/main/resources这个配置里增加了 true。这个属性非常关键,。

    filtering:决定是否将resources目录下的文件中的${xxx}进行参数替换。这里的properties就是 标签下指定的properties文件

    <resources>
                <resource>
                    <directory>src/main/javadirectory>
                    <excludes>
                        <exclude>**/*.javaexclude>
                    excludes>
                resource>
    
    
                <resource>
                    <directory>src/main/resourcesdirectory
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • 相关阅读:
    三年测试经验, 字节跳动离职后, 一口气拿到 15 家公司 Offer
    电商小程序09活动管理
    Linux服务器 james邮箱服务器搭建 (附java测试Demo)
    视野修炼-技术周刊第57期
    单词接龙 II
    vue中页面跳转白屏的解决方式,同一路由地址,参数不同跳转白屏的解决方式
    Vue3+elementplus搭建通用管理系统实例八:通用表格实现中
    RTD2513驱动板ODM/OEM方式
    基于一致性算法的微电网分布式控制MATLAB仿真模型
    浅谈大数据算法
  • 原文地址:https://blog.csdn.net/qq445829096/article/details/126951406