基于maven pom配置中的profiles配置针对不同环境,使用不同配置文件。
第一步:创建filters资源文件(src/main/filters/dev.properties、test.properties、beta.properties),其中路径地址/名称任意设置。
dev.properties
mysql.url=jdbc:mysql://xx.xx.xx.xx:3306/xx
第二步:创建配置文件(src/main/resources/settings.properties),对第一步配置资源进行使用。
settings.properties
mysql.url=${mysql.url}
可使用如下命令将配置文件导入到spring容器中
<context:property-placeholder location="classpath:settings.properties"/>
也可在spring配置文件中直接使用(src/main/resources/spring.xml)
spring.xml
<bean class="xx.xx.xx.xx.xx.xx"> <property name="url" value="${mysql.url}" /> </bean>
第三步:在pom中配置profile
pom.xml
<profiles> <profile> <id>dev</id> <build> <filters> <filter>src/main/filters/dev.properties</filter> </filters> </build> <!-- 定义其为默认加载 --> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <build> <filters> <filter>src/main/filters/test.properties</filter> </filters> </build> </profile> <profile> <id>beta</id> <build> <filters> <filter>src/main/filters/beta.properties</filter> </filters> </build> </profile>
将其添加到pom的<project>标签内部。
第四步(关键一步):maven打包时激活filters过滤。
pom.xml
<build> <!-- 定义项目打包后的名称 --> <finalName>pojo-name</finalName> <resources> <resource> <!-- 对该目录下的配置build时启用filter 过滤替换--> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </build>
第五步:执行打包命令
mvn package -P dev
其中 -P 指定编译的profile
问题分享:
在使用过程中,配置与以上配置完全相同,但始终无法对${mysql.url}等参数进行替换,最终导致的问题是,我在eclipse-->properties-->java build path-->source 配置中将src/main/resources默认编译到了src/main/webapp/WEB-INF/classes 目录下(未替换文件-错误文件),导致在执行mvn 命令时,由于未进行mvn清理,mvn是直接将src/main/webapp/WEB-INF/classes拷贝到了target/obj-name/WEB-INF/下面,而不是经过build filter重新生成的配置文件!解决方案:删除src/main/webapp/WEB-INF/classes下配置文件,让其在mvn package -P dev 时重新生成!
相关推荐
VMware vSphere 磁盘无法增加容量,报错:无法连接到Profile-Driven Storage Service
Mesh Profile Specification Mesh Model Specification Mesh Device Properties
Mesh Profile(网状配置文件): 定义了基本要求,以实现用于蓝牙LE无线技术的可互操作的网状网络解决方案 Model Specification: 介绍模型,用于定义mesh网络上节点的基本功能 Device Properties: 定义mesh模型...
.profile(由Bourne Shell和Korn Shell使用)和.login(由C Shell使用)两个文件是.bash_profile的同义词,目的是为了兼容其它Shell。在Debian中使用.profile文件代 替.bash_profile文件。 2..bashrc文件会在bash shell...
userprofileservice服务未能登陆,无法加载用户配置文件.pdf
VsCode配置-profile
报错libpng warning: iCCP: known incorrect sRGB profile的问题
/etc/profile 每个用户,首次登录时被执行; /etc/bashrc 每个运行bash shell的用户都执行此文件,当bsh被打开时,该文件被读取; ~/.bash_profile 专用于本用户的shell信息,仅被执行一次; ~/.bashrc 文件包含本...
Statistical profile monitoring is an area of statistical quality control that is growing in significance for researchers and practitioners, specifically because of its range of applicability across ...
linux /etc/profile 文件的改变会涉及到系统的环境,也就是有关 Linux 环境变量的东西,学习 Linux 要了解 Linux profile 文件的相关原理, 这里对则以文件进行具体分析
蓝牙Mesh Profile,Mesh_Model_Specification v1.0,Mesh Device Properties v1.0
在plsql中,进行profile的创建,了解简单的profile内容
图像处理ICC文件:Generic CMYK Profile.icc 和 Generic RGB Profile.icc
android_实时获取蓝牙profile连接状态.pdfandroid_实时获取蓝牙profile连接状态.pdfandroid_实时获取蓝牙profile连接状态.pdfandroid_实时获取蓝牙profile连接状态.pdfandroid_实时获取蓝牙profile连接状态.pdf...
win7 profile修复
环境特定配置文件:application-{profile}.properties(或application-{profile}.yml) 2. 使用属性文件(.properties)格式进行配置 在默认配置文件中,按照属性键值对的格式配置应用程序的属性。例如: properties...
参考"解决问题:libpng warning: iCCP: known incorrect sRGB profile"[https://blog.csdn.net/WangJiankun_ls/article/details/79470739]文章,通过自己实践操作,得出结论,希望能帮助到你们
Personal Profile
Neor Profile SQL 汉化文件,兼容版本4.1 安装原版后,将文件放入languages文件夹下,从setting中选择Chinese即可