首页 > 解决方案 > 禁用 Spring Boot 参数解析

问题描述

我想完全禁用 SpringBoot 参数解析。有什么办法吗?

为什么?

我的工具的用法是这样的: $ mytool --some-option=value -- --some-other-option=value arg1 arg2

注意--.

按照惯例(参见准则 10),它用作选项和操作数之间的分隔符。

目前,BootDefaultArgument认为这是一个名称无效的参数,并且会出错。

我打开了一个 Spring Boot问题来处理--以下约定。但与此同时,我想完全禁用参数解析,因为无论如何我都没有使用它。

我认为这是不可能2.0.x,但我想与更熟悉的人确认。可能对解决这个问题有一些想法。

示例跟踪

java.lang.IllegalArgumentException: Invalid argument syntax: -- at org.springframework.core.env.SimpleCommandLineArgsParser.parse(SimpleCommandLineArgsParser.java:75) at org.springframework.core.env.SimpleCommandLinePropertySource.<init>(SimpleCommandLinePropertySource.java:90) at org.springframework.boot.DefaultApplicationArguments$Source.<init>(DefaultApplicationArguments.java:76) at org.springframework.boot.DefaultApplicationArguments.<init>(DefaultApplicationArguments.java:42) at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) at com.mypackage.genie.MyApplication.run(MyApplication.java:63) (...)

标签: javaspring-bootcommand-line-interface

解决方案


如果您不希望 Spring Boot 解析参数,您可以更改您的 main 方法,以便它们不会传递到SpringApplication.run(). 然后,您可以在运行应用程序之前或之后自行在 main 方法中处理参数。


推荐阅读