问题描述
我在基于Java的配置文件中有批处理作业定义.我已经看到 CommandLineJobRunner
可用于启动作业,但是作业定义应在.xml中定义.我想使用 CommandLineJobRunner
来运行基于Java的配置中定义的作业.
I have my batch job definition in Java based configuration file. I have seen that CommandLineJobRunner
can be used to launch job, but the job definition should be defined in .xml. I want to use CommandLineJobRunner
to run my jobs defined in java based configuration.
根据此处的文档: https://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html#commandLineJobRunner ,没有详细说明.
According to the documentation here: https://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html#commandLineJobRunner, there is no details to do so.
我们还能做到吗?还有什么其他选择?
Can we even do this? What can be the other alternatives?
推荐答案
CommandLineJobRunner
的第一个参数可以是:
The first argument of CommandLineJobRunner
can be either:
- 包含作业定义的xml文件
- 或包含作业定义的配置类的标准名称
从Spring Batch v4开始,每个文档页面的顶部都有一个切换开关,可让您显示Java或Xml配置中的示例.例如,当切换开关设置为"Java"时,此处的文档部分: https://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#runningJobsFromCommandLine 显示了如何使用 CommandLineJobRunner 带有Java配置类的code>:
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. 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 -cp your/class/path org.springframework.batch.core.launch.support.CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay schedule.date(date)=2007/05/05
io.spring.EndOfDayJobConfiguration
是包含 endOfDay
作业定义的完全限定的类名.
io.spring.EndOfDayJobConfiguration
is the fully qualified class name containing the endOfDay
job definition.
这篇关于如何使用具有Java配置的CommandLineJobRunner启动Spring Batch Job的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!