Maven spring boot 带参数运行调试 [英] Maven spring boot run debug with arguments

查看:52
本文介绍了Maven spring boot 带参数运行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我使用命令运行我的 Spring Boot 应用程序:

Usually I'm running my Spring Boot application with command:

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

I want to set custom port to debug, so I can connect from eclipse. When I add arguments from example 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.portpath.to.config.dir 不再被识别,我得到如下异常:

it works but other arguments like server.port or path.to.config.dir are no longer recognized and I get exception like:

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"

问题:如何使用所有参数运行?

Question: How I can run with all arguments?

推荐答案

您注意到的行为和变化正在发生,因为您开始使用 jvmArguments 选项:

The behavior and the change you notice is happening because you started using the jvmArguments option:

应该与用于运行应用程序的分叉进程相关联的 JVM 参数.在命令行中,确保在引号之间包含多个值.

JVM arguments that should be associated with the forked process used to run the application. On command line, make sure to wrap multiple values between quotes.

默认情况下,当使用它时,Spring Boot Maven 插件也会分叉其执行,如fork 选项:

By default, when using it, the Spring Boot Maven plugin will also fork its execution, as described by the fork option:

用于指示是否应分叉运行进程的标志.默认情况下,进程分叉仅在指定了代理或 jvmArguments 时使用.

Flag to indicate if the run processes should be forked. By default process forking is only used if an agent or jvmArguments are specified.

因此,jvmArguments 的使用也激活了插件执行的 fork 模式.通过分叉,您实际上并没有选择从命令行传递的其他 -D 参数.

Hence, the usage of jvmArguments also activated the fork mode of the plugin execution. By forking, you are actually not picking up the others -D arguments passed from command line.

解决方案:如果您想使用 jvmArguments,请将所有必需的参数传递给它.

Solution: if you want to use the jvmArguments, then pass all of the required arguments to it.

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8787 -Dserver.port=9090 -Dpath.to.config.dir=/var/data/my/config/dir"

-- 编辑 22/09/2020另请检查@Stephane 的其他答案以补充此答案(参数前缀)

-- Edit 22/09/2020 Check also the other answer from @Stephane to complent this answer (prefix of parameters)

这篇关于Maven spring boot 带参数运行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆