您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Spring Boot中从命令行设置活动配置文件和配置位置

在Spring Boot中从命令行设置活动配置文件和配置位置

你可以通过两种方法在命令行上添加/覆盖spring属性

选项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拾取配置文件和配置位置。

Java 2022/1/1 18:20:17 有421人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶