如何从命令行启动位于 spring 引导项目中的 spring 批处理?

How to launch from the command line a spring batch located inside a spring boot project?

我正在使用 spring boot 2.3,其中有一些 spring 批处理配置。

目前,如果我想 运行 一个 spring 批处理,我使用了以下方法

Spring 批处理作业配置

@Configuration("myJobConf")
@JobReference("myJob")
public class MyJob

application.yml

spring:
  batch:
    job:
      enabled: true
      names: ${JOB_NAME}

当我想从命令行启动 spring 批处理时,我 运行

java -jar mySpringBootApplication.jar -DJOB_NAME=myJob

但现在我还需要传递一些作业参数。 我该怎么做?

谢谢

But now I need to pass some job parameters also. How can I do that?

您可以将作业参数作为 key/value 对传递:

java -jar mySpringBootApplication.jar -DJOB_NAME=myJob param1=value1 param2=value2

您可以在参考文档的 Batch Applications -> Running from the Command Line 部分找到更多详细信息。