java - 禁用 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)
(...)
解决方案
如果您不希望 Spring Boot 解析参数,您可以更改您的 main 方法,以便它们不会传递到SpringApplication.run()
. 然后,您可以在运行应用程序之前或之后自行在 main 方法中处理参数。
推荐阅读
- three.js - 在three.js WebGL中创建放大镜效果
- web-services - Web 服务响应 SetValues 给 Ljava.lang.Object;@ 在电子表格中
- mysql - 表内连接未显示预期结果
- php - 我做错了什么?“定时任务”
- typescript - TypeScript 错误 TS2403:后续变量声明必须具有相同的类型
- python - pyspark 在 Jupyter notebook 中打开而不是 shell
- qt - Flow 底部的额外空间
- php - 返回 NULL 而不是字符串的抽象函数 - PHP OOP
- unity3d - 从另一个对象的输入触发动画的最佳方法是什么?
- godot - 水平和垂直翻转动画精灵的单帧