文件命名要求
必须满足 application-xxx.properties 的格式。约定为:
- application.properties 通用配置。
- application-dev.properties 开发配置。
- application-test.properties 测试配置,配置了跟测试环境(测试服务器)有关的信息。
- application-prod.properties 生产配置,当系统交付以后,部署到生还环境服务器上以后需要用到。
- application-username.properties 开发人员自己使用的配置,通常不提交到库上。
使用配置文件的方法
方法一
在application.properties中指定生效的配置:
spring.profiles.active=test
方法二
在命令行中指定:
java -jar xxx.jar --spring.profiles.active=test
打包的方法
mvnw clean package -DskipTests -Ptest
或
mvnw clean install -DskipTests -Ptest