springbatch的使用

一、相关注解

使用springbatch需要设置一些注解,方便使用

@EnableBatchProcessing :自动补全一些相关属性

EnableBatchProcessing provides a base configuration for building batch jobs. Within this base configuration, an instance of StepScope is created in addition to a number of beans made available to be autowiredobRepository:
bean name “jobRepository”
JobLauncher: bean name “jobLauncher”
JobRegistry: bean name “jobRegistry”
PlatformTransactionManager: bean name “transactionManager”
JobBuilderFactory: bean name “jobBuilders”
StepBuilderFactory: bean name “stepBuilders”

Configuring and Running a Job
@ JobScope:在任务实例化的时候创建Bean,开启延迟Bean实例功能

Because it is not part of the Spring container by default, the scope must be added explicitly, by using the batch namespace, by including a bean definition explicitly for the JobScope, or using the @EnableBatchProcessing annotation。

因为默认情况下它不是Spring容器的一部分,所以必须通过使用批处理名称空间、通过为JobScope显式包含bean定义或使用@EnableBatchProcessing注释显式添加作用域
@StepScope:在step被使用时创建Bean,开启延迟加载功能

Using a scope of Step is required in order to use late binding, because the bean cannot actually be instantiated until the Step starts, to allow the attributes to be found. Because it is not part of the Spring container by default, the scope must be added explicitly, by using the batch namespace or by including a bean definition explicitly for the StepScope, or by using the @EnableBatchProcessing annotation. Use only one of those methods.

为了使用后期绑定,需要使用Step的作用域,因为只有在Step开始之前,bean才能被实际实例化,从而允许找到属性。一般情况下,这个bean不属于spring容器的内容,以必须显式地添加作用域。方法是使用批处理名称空间或显式地为StepScope包含一个bean定义,或使用@EnableBatchProcessing注释。使用其中一种方法。

二、在不同steps间传递数据

1、自定义全局类

将需要的参数设置为static对象,job开始之前进行初始化。
通过set方法将参数设置进去,通过get方法获得

2、通过JobParameters

通过JobParametersBuilder.addString()添加,不过只能添加String类型或者数值类型参数,无法传递复杂对象。

3、使用jobContext

使用stepExecution和jobExecution设置参数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值