Spring Boot 2.0.3整合Spring Batch

本文介绍了如何在Spring Boot 2.0.3中整合Spring Batch进行大数据处理。通过在Spring Initializr选择相关依赖,自定义配置类启用Batch处理,并详细阐述了批处理流程,包括reader、processor、writer的设置。此外,还展示了如何使用Controller测试job,配置MySQL数据源,初始化数据库表,以及如何设置定时任务来周期性执行job。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Batch用来做大数据处理,是一项不错的选择,由于公司的整体架构是Spring Boot,因此自己研究了一下两者之间的关系。

1.在官网http://start.spring.io/,选择MYSQL,BATCH,WEB

2.自定义MyBatchConfig类,添加注解@Configuration--配置注解,@EnableBatchProcessing--batch注解,相关代码如下:

package com.kmm.config;

import com.kmm.bean.Person;
import com.kmm.listener.MyJobListener;
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.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.item.*;
import org.springframework.batch.support.DatabaseType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.util.List;

@Configuration
@EnableBatchProcessing
public class MyBatchConfig {
    @Bean
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值