You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用spring-boot:run时,如何在命令行设置Spring Boot激活配置文件?

Spring Boot 1.5 + Maven 3.8 + Windows PowerShell 启动指定Profile的正确命令

针对你的场景,有两种可行的正确命令:

方法1:使用Spring Boot Maven插件1.x版本专属参数

mvn -Drun.profiles=dev spring-boot:run

Spring Boot 1.x系列的Maven插件采用run.profiles作为启动时指定Profile的参数名,而非2.x版本的spring-boot.run.profiles,这是你原本命令出错的核心原因之一。

方法2:直接设置JVM系统属性spring.profiles.active

mvn -Dspring.profiles.active=dev spring-boot:run

这种方式更通用,直接通过JVM系统属性指定激活的Profile,Spring Boot会自动识别并加载对应配置。

PowerShell特殊处理说明

如果命令中-D后的参数包含连字符(比如误写的spring-boot.run.profiles),PowerShell会将连字符后的内容误解析为新的命令参数,导致Maven将其识别为无效的生命周期阶段。此时需要将整个-D参数用双引号包裹:

mvn "-Dspring-boot.run.profiles=dev" spring-boot:run

但注意这种写法仅适用于Spring Boot 2.x及以上版本的插件,你的1.5版本不支持该参数名,因此更推荐前面两种方法。

内容的提问来源于stack exchange,提问作者Dave

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 00:06:24