当前位置:
凯发k8官方网 >
前端技术
> javascript
>内容正文
javascript
springbatch接口batchconfigurer详解 -凯发k8官方网
凯发k8官方网
收集整理的这篇文章主要介绍了
springbatch接口batchconfigurer详解
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
前言:batchconfigurer作为策略接口提供了自定义springbatch基础设施组件能力。在使用@enablebatchprocessing注解后,即可获取每个springbatch基础设施组件实例。
batchconfigurer接口
当程序使用了@enablebatchprocessing注解时,springbatch会执行以下流程。首先通过batchconfigurer接口的实现来创建这些bean,然后通过simplebatchconfigurationt将它们添加到spring applicationcontext中。
batchconfigurer接口方法
batchconfigurer提供了四个方法,每个方法都是为springbatch基础设施提供了一个主要组件。
- jobrepository操作springbatch元数据库增删改查
- joblauncher启动springbatch作业入口
- platformtransactionmanager 为springbatch提供所有的事务管理
- jobexplorer提供了针对作业存储库中所保存数据的只读视图
自定义batchconfigurer
如果默认的defaultbatchconfigurer不满足业务现状需要我们自定义batchconfigurer。其实我们自定义的batchconfigurer主要是要从写defaultbatchconfigurer类里面方法实现。
/*** @author: slzhao* @date 2021/11/1122:17*/ public class custombatchconfigurer extends defaultbatchconfigurer {@resource(name = "respdatasource")private datasource datasource;@autowiredprivate platformtransactionmanager platformtransactionmanager;@overridepublic platformtransactionmanager gettransactionmanager() {return platformtransactionmanager;}@overrideprotected jobexplorer createjobexplorer() throws exception {jobexplorerfactorybean jobexplorerfactorybean = new jobexplorerfactorybean();jobexplorerfactorybean.setdatasource(this.datasource);jobexplorerfactorybean.settableprefix("zsl_");jobexplorerfactorybean.afterpropertiesset();return jobexplorerfactorybean.getobject();}@overrideprotected joblauncher createjoblauncher() throws exception {return super.createjoblauncher();}@overrideprotected jobrepository createjobrepository() throws exception {jobrepositoryfactorybean factory = new jobrepositoryfactorybean();factory.setdatasource(this.datasource);factory.settableprefix("zsl_");factory.settransactionmanager(platformtransactionmanager);factory.afterpropertiesset();return factory.getobject();} }注意:由于jobrepository和jobexplorer使用相同的底层数据存储,因此同时配置它们确保一直。
总结
以上是凯发k8官方网为你收集整理的springbatch接口batchconfigurer详解的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: springbatch批处理框架入门(二
- 下一篇: springbatch处理器script