春季批处理,在何处/如何保存有关作业的元数据

时间:2018-07-08 00:10:33

标签: spring spring-batch

如何设置用于元数据的任何外部数据库(mysql,postgres,我现在不关心哪个数据库)?

目前,我有春季批处理,将作业结果写入Mongodb,并且工作正常,但是我没有跟踪作业状态,因此即使每次中断都从头开始运行作业。

有很多避免这种情况的示例,但是似乎无法找到一个明确的答案,说明我需要配置什么以将元数据发送到实际而非内存中。

我尝试添加属性文件,但没有效果

#    for Postgres:
batch.jdbc.driver=org.postgresql.Driver
batch.jdbc.url=jdbc:postgresql://localhost/postgres
batch.jdbc.user=postgres
batch.jdbc.password=mysecretpassword
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer
batch.schema.script=classpath:/org/springframework/batch/core/schema-postgresql.sql
batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-postgresql.sql
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=

1 个答案:

答案 0 :(得分:1)

  

有很多避免这种情况的示例,但是似乎无法找到明确的答案,说明我需要进行配置以将元数据发送到实际位置而不是内存中。

您需要在批处理应用程序上下文中配置类型为DataSource的bean(或扩展DefaultBatchConfigurer并设置要用于存储元数据的数据源)。

这里有很多示例:https://github.com/spring-projects/spring-batch/tree/master/spring-batch-samples

您可以在此处找到数据源配置:https://github.com/spring-projects/spring-batch/blob/master/spring-batch-samples/src/main/resources/data-source-context.xml