简体   繁体   English

如何使用具有 Java 配置的 CommandLineJobRunner 启动 Spring Batch Job

[英]how to launch Spring Batch Job using CommandLineJobRunner having Java configuration

I have my batch job definition in Java based configuration file.我在基于 Java 的配置文件中定义了批处理作业。 I have seen that CommandLineJobRunner can be used to launch job, but the job definition should be defined in.xml.我已经看到CommandLineJobRunner可用于启动作业,但作业定义应在 .xml 中定义。 I want to use CommandLineJobRunner to run my jobs defined in java based configuration.我想使用CommandLineJobRunner来运行我在基于 Java 的配置中定义的作业。

According to the documentation here: https://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html#commandLineJobRunner , there is no details to do so.根据此处的文档: https ://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html#commandLineJobRunner,没有这样做的详细信息。

Can we even do this?我们甚至可以这样做吗? What can be the other alternatives?还有什么其他选择?

The first argument of CommandLineJobRunner can be either: CommandLineJobRunner的第一个参数可以是:

  • The xml file containing the job definition包含作业定义的 xml 文件
  • Or the fully qualified name of the configuration class containing the job definition或者包含作业定义的配置类的完全限定名称

Starting from Spring Batch v4, there is a toggle on the top of each documentation page that allows you to show examples in Java or Xml config.从 Spring Batch v4 开始,每个文档页面顶部都有一个切换开关,允许您在 Java 或 Xml 配置中显示示例。 For example, when the toggle is set to "Java", the documentation section here: https://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#runningJobsFromCommandLine shows how to use the CommandLineJobRunner with a Java configuration class:例如,当切换设置为“Java”时,此处的文档部分: https ://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#runningJobsFromCommandLine 显示了如何使用带有 Java 配置类的CommandLineJobRunner

$>java -cp your/class/path org.springframework.batch.core.launch.support.CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay schedule.date(date)=2007/05/05

io.spring.EndOfDayJobConfiguration is the fully qualified class name containing the endOfDay job definition. io.spring.EndOfDayJobConfiguration是包含endOfDay作业定义的完全限定类名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM