1 pom.xml 添加 profiles 标签
<profiles> <!--pro 线上环境--> <profile> <id>hdapp_pro</id> <properties> <db.main.url>jdbc:oracle:thin:@ip:1521:orcl</db.main.url> <db.mian.username>username</db.mian.username> <db.main.password>password</db.main.password> </properties> <activation> 配置默认使用哪个环境 <activeByDefault>true</activeByDefault> </activation> </profile> <!-开发环境环境--> <profile> <id>hdapp_dev</id> <properties> <db.main.url>jdbc:oracle:thin:@ip:1521:orcl</db.main.url> <db.mian.username>username</db.mian.username> <db.main.password>password</db.main.password> </properties> </profile> </profiles>
2 在resources 下新配置文件 jdbc.properties 内容如下
jdbc.url = ${db.main.url}
jdbc.username =${db.mian.username}
jdbc.password =${db.main.password}
3 在pom.xml build 中添加扫描的文件
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources/</directory>
<includes> //可以写多个
<include>config/jdbc.properties</include>
<include>quartz/scan-quartz.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
4 打包时指定profiles 即可
打包命令添加参数 -P
clean package -P hdapp_dev