选项1:Java系统属性(VM参数) 重要的是-D参数应位于application.jar之前,否则无法识别。
java -jar -Dspring.profiles.active=prod application.jar
选项2:程序参数
java -jar application.jar --spring.profiles.active=prod --spring.config.location=c:\config
bootRun {
String activeProfile = System.properties['spring.profiles.active']
String confLoc = System.properties['spring.config.location']
systemProperty "spring.profiles.active", activeProfile
systemProperty "spring.config.location", "file:$confLoc"
}
现在,bootRun拾取配置文件和配置位置。