欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 前端技术 > javascript >内容正文

javascript

springbatch适配器详解 -凯发k8官方网

发布时间:2025/1/21 javascript 18 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 springbatch适配器详解 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

一、springbatch适配器

1、springbatch分别有读(reader)、处理(processor)、写(writer)、tasklet处理器。

  • 读适配器:itemreaderadapter
  • 处理适配器:itemprocessoradapter
  • 写适配器:itemwriteradapter
  • tasklet适配器:methodinvokingtaskletadapter

2、springbatch之所以给我们开这么多适配器原因是让我们把既有的服务作为参数传到适配器里面,避免开发重复代码。不得不说springbatch开发人员想的真周到。

3、springbatch适配器都有三个公共的方法:

  • public object targetobject (目标对象,将要调用的实例)
  • public string targetmethod(目标方法,将要在实例上调用的方法)
  • public object[] arguments(配置选型,用于提供一组数组类型参数)

二、springbatch适配器实战(tasklet举例)

演示methodinvokingtaskletadapter适配器

1、创建job配置taskletadapterconfiguration 

@configuration @enablebatchprocessing public class taskletadapterconfiguration {@autowiredprivate jobbuilderfactory jobbuilderfactory;@autowiredprivate stepbuilderfactory stepbuilderfactory;@autowiredpublic peopleservice peopleservice;@beanpublic job taskletadapterjob() {return jobbuilderfactory.get("taskletadapterjob").start(taskletadapterstep()).build();}@beanpublic step taskletadapterstep() {return stepbuilderfactory.get("taskletadapterstep").tasklet(methodinvokingtaskletadapter()).build();}@beanpublic methodinvokingtaskletadapter methodinvokingtaskletadapter() {methodinvokingtaskletadapter adapter = new methodinvokingtaskletadapter();adapter.settargetobject(peopleservice);adapter.settargetmethod("uppercase");adapter.setarguments(new object[]{new people("lee","10","北京","1233")});return adapter;}}

2、tasklet适配器执行的目标类和方法

@service public class peopleservice {public people uppercase(people people) {people p = new people();p.setname(people.getname().touppercase(locale.root));p.setadress(people.getadress().touppercase(locale.root));p.setage(people.getage());p.setidcard(people.getidcard());system.out.println("p:" p);return p;} }

3、适配器执行目标方法一定要先看看有没有参数,如果有参数一定要把此方法(setarguments)设置上,否则会报"no matching arguments found for method"异常

4、执行结果如图所示:

总结

以上是凯发k8官方网为你收集整理的springbatch适配器详解的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图