Spring Batch入门实例


在对Spring Batch深入学习前,先写一个小的demo,增加对Spring Batch的了解

相关信息

开发环境:
JDK 1.8.0_201
apache-maven-3.3.9
IntelliJ IDEA 2019.2.1 (Community Edition)

版本信息
Spring Batch 3.0.10.RELEASE
Spring test 4.3.21.RELEASE

相关概念

领域对象 描述
Job Repository 作业仓库,负责Job,Step执行过程中的状态保存
Job launcher 作业调度器,提供执行Job的入口
Job 作业,由多个Step组成,封装整个批处理操作
Step 作业步,Job的一个执行环节,由多个或者一个Step组装成Job
Tasklet Step中具体执行逻辑的操作,可以重复执行,可以设置具体的同步、异步操作等
Chunk 给定数量Item的集合,可以定义对Chunk的读操作、处理操作、写操作,提交间隔等,这是Spring Batch框架的一个重要特征
Item 一条数据记录
ItemReader 从数据源(文件系统、数据库、队列等)中读取Item
ItemProcessor 在Item写入数据源之前,对数据进行处理(如:数据清洗、数据转换、数据过滤、数据校验等)
ItemWriter 将Item批量写入数据源(文件系统、数据库、队列等)

demo背景

通过Spring Batch来读取csv文件,读完后再将读到的数据写入另一个csv文件

代码展示

项目结构

在这里插入图片描述

配置pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.et</groupId>
    <artifactId>spring-batch-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>spring-batch-demo</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>3.0.10.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.3.21.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值