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

时间:2018-03-13 07:23:06

标签: java spring-boot spring-batch

我在基于Java的配置文件中有我的批处理作业定义。我已经看到CommandLineJobRunner可用于启动作业,但作业定义应在.xml中定义。我想使用CommandLineJobRunner来运行在基于java的配置中定义的作业。

根据此处的文档:https://docs.spring.io/spring-batch/trunk/reference/html/configureJob.html#commandLineJobRunner,没有详细说明。

我们甚至可以这样做吗?还有什么其他选择?

1 个答案:

答案 0 :(得分:1)

CommandLineJobRunner的第一个参数可以是:

  • 包含作业定义的xml文件
  • 或包含作业定义的配置类的完全限定名称

从Spring Batch v4开始,每个文档页面顶部都有一个切换,允许您在Java或Xml配置中显示示例。例如,当切换设置为“Java”时,此处的文档部分:https://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#runningJobsFromCommandLine显示如何将CommandLineJobRunner与Java配置类一起使用:

$>java CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay schedule.date(date)=2007/05/05

io.spring.EndOfDayJobConfiguration是包含endOfDay作业定义的完全限定类名。