• 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
  • 相关阅读:
    FIX三天日记-quick fix简介
    基于Java+JSP+MySQL基于SSH的扶贫信息管理系统-计算机毕业设计
    集群脑裂导致数据丢失怎么办?
    redis的原理和源码-sentinel哨兵的原理和源码解析(上)
    摩尔信使MThings的协议转换(数据网关)功能
    如何把PDF转换成Word文档?给大家分享三种转换方法
    说一说PCIe5.0的速率和带宽
    vue面试相关知识
    mysql innodb 存储引擎
    跨域?如何解决?同源策略?
  • 原文地址:https://blog.csdn.net/qq445829096/article/details/126951406