UrlReader) and you can pass it on. The output you receive from Yahoo! is in CSV format already, so your
ItemWriter becomes significantly simplified. In this case, because your item is a String , using the
FlatFileItemWriter with a PassThroughLineAggregator works perfectly. Listing 10-23 shows the
configuration for this ItemWriter.
Listing 10-23. The stockFileWriter Configuration
<beans:bean id="stockFile" class="org.springframework.core.io.FileSystemResource">
<beans:property name="resource" ref="stockFile" />
You can't get much simpler for an ItemWriter. By providing a file to write to and using a String as
the item, there is nothing for Spring Batch to do other than write the String to the file. Short, sweet, and
to the point.
When you build and run the job with only the first and second steps fully functional, the end result
of step 2 is a CSV file that looks like what is shown in Listing 10-24.
Listing 10-24. Output of Step 2
As you can see, the file consists of the stock ticker followed by the closing price of the previous day.
The next section looks at the process of importing this file into your Ticker table.
Importing Current Stock Prices
In the previous step, you read the results of a web service call and wrote it to disk to import. You might
be wondering, why not just read it straight into the database? The main reason is that if something goes
wrong with the import step (after you've successfully downloaded the stock prices), you don't have to
rerequest the prices. Once you've successfully received the stock prices, you can skip step 2 if the import