• 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
  • 相关阅读:
    RabbitMQ: return机制
    金蝶云苍穹融资租赁系统V5.0发布。
    PIE-Engine 教程:水稻面积提取3—sentinel2合成月度影像宿迁市)
    web前端期末大作业 html+css+javascript汽车销售网站 学生网页设计实例 企业网站制作
    yolo-目标检测算法简介
    国内40多家金融机构数据被窃,多家知名基金上榜
    RedisSearch深度解析:探索全文搜索的新境界
    【代码源】每日一题 国家铁路
    解决Error in rawToChar(block[seq_len(ns)]) :
    【CSS】transition、transform以及animation
  • 原文地址:https://blog.csdn.net/qq445829096/article/details/126951406