Java Reference
In-Depth Information
C H A P T E R 8
Item Processors
In the previous chapter, you learned how to read various types of input using the components of Spring
Batch. Obviously, obtaining the input for any piece of software is an important aspect of the project;
however, it doesn't mean much if you don't do something with it. Item processors are the component
within Spring Batch where you do something with your input. In this chapter, you will look at the
ItemProcessor interface and see how you can use it to develop your own processing of batch items.
In the “Introduction to ItemProcessors” section,,you'll start with a quick overview
of what an ItemProcessor is and how it fits into the flow of a step.
Spring Batch provides utility ItemProcessors like the ItemProcessorAdapter,
which uses existing services as your ItemProcessor implementation. In the “Using
Spring Batch's ItemProcessors” section, you'll take and in-depth look at each of
the processors the framework provides.
In many cases, you will want to develop your own ItemProcessor implementation.
In the “Writing Your Own ItemProcessors” section, you will look at different
considerations as you implement an example ItemProcessor.
A common use of an ItemProcessor is to filter out items that were read in by an
ItemReader from being written by the step's ItemWriter. In the “Filtering Items”
section, you'll look at an example of how this is accomplished.
Introduction to ItemProcessors
In Chapter 7, you looked at ItemReaders, the input facility you use within Spring Batch. Once you have
received your input, you have two options. The first is to just write it back out as you did in the examples
in the last chapter. There are many times when that will make sense. Migrating data from one system to
another or loading data into a database initially are two examples of where reading input and writing it
directly without any additional processing makes sense.
However, in most scenarios, you are going to need to do something with the data you read in.
Spring Batch has broken up the pieces of a step to allow a good separation of concerns between reading,
processing, and writing. Doing this allows you the opportunity to do a couple unique things, such as the
following:
 
Search WWH ::




Custom Search