Spring Batch with Java Config: An Example

Enterprises tend to be large, old institutions. They have done a lot of stuff, and they have a lot of data under their belts. When we’re working with enterprises to build apps that will help them understand their data, we need a way to process that data that takes time and system limitations into account. We can often process a lot of stuff at once more efficiently by using batch jobs. Spring Batch gives us a convenient tool to perform batch processing in Spring applications.

If you are new to Batch and would like to learn about some of the use cases for the tool, I would recommend section 1.2 of the documentation. If you would like an overview of Batch and you want to understand how it performs batch jobs at the top level, I recommend Chapter 2 of the book Pro Spring Batch

I have been working on sample configuration for a theoretical Spring Integration application, and since I have also been working with Batch it made sense to provide a sample configuration for batch, too.

The following batch configuration goes with an app that solves a business problem for a book club. The book club has been around since the early days of the internet and has all of its data on its members stored in XML files. Now, they want to add the birthdays of each of their members to the file system so they can create alerts on their members’ birthdays, offer discounts from sponsoring organizations for members on their birthdays, or collate member age data. The book club has discovered that it can fetch member birthdays from a Facebook API using member information that they already have in the system.

The book club has a giant XML file called all_members.xml. This app will take those XML records in batches of 5, make the call to get the birthdays, add the birthday to each member, and then print out each member’s birthday.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s