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

查看:1392
本文介绍了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连接。当我从示例 http://docs.spring.io/spring-boot/docs/1.1.2.BUILD-SNAPSHOT/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 http://docs.spring.io/spring-boot/docs/1.1.2.BUILD-SNAPSHOT/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 不再被识别,我得到例外:

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参数。在命令行中,make确保在引号之间包装多个值。

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 时才使用进程分叉。

因此, 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"

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

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