通常我使用命令运行我的 Spring Boot 应用程序:
mvn spring-boot:run -Drun.arguments=--server.port=9090 \
-Dpath.to.config.dir=/var/data/my/config/dir
我想将自定义端口设置为调试,这样我就可以从 Eclipse 连接。当我从示例 https://docs.spring.io/spring-boot/docs/1.1.2.RELEASE/maven-plugin/examples/run-debug.html 添加参数时
mvn spring-boot:run -Drun.arguments=--server.port=9090 \
-Dpath.to.config.dir=/var/data/my/config/dir \
-Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787"
它有效,但其他参数如 server.port
或 path.to.config.dir
不再被识别,我得到如下异常:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class [com.my.app.Controller]; nested exception
is java.lang.IllegalArgumentException: Could not resolve placeholder
'path.to.config.dir' in string value
file:///${path.to.config.dir}/some.properties"
问题:我如何运行所有参数?
原文由 wbk 发布,翻译遵循 CC BY-SA 4.0 许可协议
您注意到的行为和变化正在发生,因为您开始使用
jvmArguments
选项:默认情况下,在使用它时,Spring Boot Maven 插件也会分叉其执行,如
fork
选项所述:因此,使用
jvmArguments
也激活了插件执行的 fork 模式。通过分叉,您实际上并没有获取其他-D
从命令行传递的参数。解决方案:如果你想使用
jvmArguments
,然后将所有必需的参数传递给它。-- 编辑 22/09/2020 还检查@Stephane 的其他答案以完成此答案(参数前缀)