Spring Batch 简明教程
Spring Batch - Application
本教程中几乎所有示例都包含以下文件 −
Almost all the examples in this tutorial contain the following files −
-
Configuration file (XML file)
-
Tasklet/processor (Java class)
-
Java class with setters and getters (Java class (bean))
-
Mapper class (Java class)
-
Launcher class (Java class)
Configuration File
配置文件 (XML) 包含以下 −
The configuration file (XML) contains the following −
-
The job and step definitions.
-
Beans defining readers and writers.
-
Definition of components like JobLauncher, JobRepository, Transaction Manager, and Data Source.
在我们的示例中,为了更好的理解,我们将其分为两个文件,即 job.xml 文件(定义 job、step、reader 和 writer)和 context.xml 文件(job launcher、job repository、transaction manager 和 data source)。
In our examples, for better understanding, we have divided this in to two files the job.xml file (defines job, step, reader and writer) and context.xml file (job launcher, job repository, transaction manager and data source).
Mapper Class
Mapper 类根据 reader 来实现 row mapper 、 field set mapper 等接口。它包含从 reader 获取数据并将它设置为带 setter 和 getter 方法的 Java 类(Java Bean)的代码。
The Mapper class, depending upon the reader, implements interfaces such as row mapper, field set mapper, etc. It contains the code to get the data from the reader and to set it to a Java class with setter and getter methods (Java Bean).
Java Bean Class
带 setters 和 getters 的 Java 类(Java bean)表示具有多个值的数据。它作为一个帮助类。我们通过该类的对象的形式传递数据从一个组件(reader、writer、processor)到另一个组件。
A Java class with setters and getters (Java bean) represents data with multiple values. It acts as a helper class. We will pass the data from one component (reader, writer, processer) to other in the form of object of this class.
Tasklet/processor
Tasklet/processor 类包含 Spring Batch 应用程序的处理代码。processor 是一个接受包含读取数据、处理它并以对象形式返回处理数据的对象(in the form object) 的类。
The Tasklet/processor class contains the processing code of the Spring Batch application. A processor is a class which accepts an object that contains the data read, processes it, and returns the processed data (in the form object).