当前位置:
凯发k8官方网 >
前端技术
> javascript
>内容正文
javascript
springbatch tasklet实现和用法(十) -凯发k8官方网
凯发k8官方网
收集整理的这篇文章主要介绍了
springbatch tasklet实现和用法(十)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
文章目录
- 一、tasklet 类创建
- 二、创建tasklet job
前言:我们在用springbatch的时候,可能不需要reader、processor、wirter(简称rpw)来处理我们的业务逻辑,tasklet可以满足我们的要求。
springbatch其它文章直通车:
- springbatch读单个文件(flatfileitemreader)和写单个文件(flatfileitemwriter)(一)
- springbatch顺序读取多文件(multiresourceitemreader)和顺序写文件(multiresourceitemwriter)(二)
- springbatch读数据库(mybatispagingitemreader)(三)
- springbatch读文件(flatfileitemreader)写据库(mybatisbatchitemwriter)(四)
- springbatch 监听器之job监听器(jobexecutionlistener)和step监听器(stepexecutionlistener)(五)
- springbatch 监听器之chunk监听器(chunklistener)和skip监听器(skiplistener)(六)
- springbatch 多线程(taskexecutor)启动job详解 (七)
- springbatch 配置并行启动job详解 (八)
- springbatch 批处理分区(partitioner )分片(九)
代码已上传github上面地址:https://github.com/fadehub/spring-boot-learn/tree/master/spring-boot-springbatch
一、tasklet 类创建
cattasklet 实现接口tasklet
package com.sl.tasklet;import org.springframework.batch.core.stepcontribution; import org.springframework.batch.core.configuration.annotation.stepscope; import org.springframework.batch.core.scope.context.chunkcontext; import org.springframework.batch.core.step.tasklet.tasklet; import org.springframework.batch.repeat.repeatstatus; import org.springframework.stereotype.component;/*** @author shuliangzhao* @title: cattasklet* @projectname spring-boot-learn* @description: todo* @date 2019/9/16 20:02*/ @component @stepscope public class cattasklet implements tasklet {@overridepublic repeatstatus execute(stepcontribution contribution, chunkcontext chunkcontext) throws exception {//todo 可以做一些下载文件等之类的动作return null;} }二、创建tasklet job
创建tasklet job很简单,只需要在创建step时候把tasklet()加上
package com.sl.config;import com.sl.tasklet.cattasklet; import org.springframework.batch.core.job; import org.springframework.batch.core.step; import org.springframework.batch.core.configuration.annotation.enablebatchprocessing; import org.springframework.batch.core.configuration.annotation.jobbuilderfactory; import org.springframework.batch.core.configuration.annotation.stepbuilderfactory; import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration;/*** @author shuliangzhao* @title: cattaskletconfiguration* @projectname spring-boot-learn* @description: todo* @date 2019/9/16 20:22*/ @configuration @enablebatchprocessing public class cattaskletconfiguration {@autowiredprivate jobbuilderfactory jobbuilderfactory;@autowiredprivate stepbuilderfactory stepbuilderfactory;@autowiredprivate cattasklet cattasklet;@beanpublic job cattaskletjob() {return jobbuilderfactory.get("cattaskletjob").start(cattaskletstep()).build();}@beanpublic step cattaskletstep() {return stepbuilderfactory.get("cattaskletstep").tasklet(cattasklet).build();}}以上就是简单介绍tasklet创建过程,tasklet还是很有用的。希望可以帮助大家。
总结
以上是凯发k8官方网为你收集整理的springbatch tasklet实现和用法(十)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: springbatch 配置并行启动jo
- 下一篇: springbatch 读取json(j