Willie Wheeler is a Principal Applications Engineer with Expedia, working on continuous delivery, including build automation, test automation, configuration management and application performance management. He's also the lead author of the book Spring in Practice (Manning). Willie is a DZone MVB and is not an employee of DZone and has posted 23 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Started With Spring Batch 2.0

03.25.2009
| 234474 views |
  • submit to reddit

In this article we're going to take a look at Spring Batch 2.0, the latest version of the Spring Batch framework. Our approach will be strongly practical: we'll cover the key ideas without dwelling too much on the details, we'll get you up and running with one of the sample applications that ships with Spring Batch, and finally we'll take a closer look at the sample app so you can understand what's going on.

At the time of this writing Spring Batch 2.0 is actually in RC2 status, so there may be minor changes between now and the GA release.

Let's begin with an overview of Spring Batch itself.

What Is Spring Batch?

While there are lots of different frameworks for building web applications, building web services, performing object/relational mapping and so forth, batch processing frameworks are comparatively rare. Yet enterprises use batch jobs to process billions of transactions daily.

Spring Batch fills the gap by providing a Spring-based framework for batch processing. Like all Spring frameworks, it's based on POJOs and dependency injection. In addition it provides infrastructure for building batch jobs as well as execution runtimes for running them.

At the highest level, the Spring Batch architecture looks like this:

 

In figure 1, the top of the hierarchy is the batch application itself. This is whatever batch processing application you want to write. It depends on the Spring Batch core module, which primarily provides a runtime environment for your batch jobs. Both the batch app and the core module in turn depend upon an infrastructure module that provides classes useful for both building and running batch apps.

Batch processing itself is a decades-old computing concept, and as such, the domain has standard concepts, terminology and methods. Spring Batch adopts the standard approach, as shown in figure 2:

 

Here we see a hypothetical three-step job, though obviously a job can have arbitrarily many steps. The steps are typically sequential, though as of Spring Batch 2.0 it's possible to define conditional flows (e.g., execute step 2 if step 1 succeeds; otherwise execute step 3). We won't cover conditional flows in this article.

Within any given step, the basic process is as follows: read a bunch of "items" (e.g., database rows, XML elements, lines in a flat file—whatever), process them, and write them out somewhere to make it convenient for subsequent steps to work with the result. There are some subtleties around how often commits occur, but we'll ignore those for now.

With the high-level overview of Spring Batch behind us, let's jump right into the football sample application that comes with Spring Batch.

 

Published at DZone with permission of Willie Wheeler, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Grzegorz Grzybek replied on Wed, 2009/03/25 - 2:59am

Hey - where has the "Printer friendly" link gone?

Matthew Schmidt replied on Wed, 2009/03/25 - 6:30am

Good question :)  We'll take a look at putting it back.

Matthew Schmidt replied on Wed, 2009/03/25 - 9:33am in response to: Grzegorz Grzybek

Ok, it's back :)  Not all the stories have them, but the spring batch has it now and all new stories get it too :)

Grzegorz Grzybek replied on Thu, 2009/03/26 - 5:17am in response to: Matthew Schmidt

Thank You! I've missed this link :)

Andy Leung replied on Wed, 2009/04/01 - 12:38am

While SpringFramework team has done a great job, I would rather go with BPM.  Basically you can manage your BPM with scheduler or in sequence of events.  Besides, it is easy to make changes to business rules where sticking with batch means to going back to COBOL+JCL Java version?

I've played with NetBeans' BPEL plugin and I think it's awesome!  I think I can spare more time on data schema validations and requirement verifications than pure coding to end of the world for batch processing.

Just my 2 cents though,

:)

Tariq Ahsan replied on Wed, 2009/05/06 - 10:13am

Hi, I am a newbie to Spring and Spring Batch Framework. We are currently trying to evaluate Spring Batch for our legacy batch conversion project. Anyway, we are currently using MyEclipse 5.0 for our IDE and having problem even to get started with the downloaded org.springframework.batch-2.0.0.RELEASE-with-dependencies.zip to use the version without Maven. Now I created a Java project in my workspace and imported the unzipped version of the above download. Could not clearly follow Spring Batch build instruction. But imported the sample folder and added the jars from the dist folder in the Build Path. But can't get a clean build. But I was able to do all that in my personal laptop where I use just the Eclipse where I didn't have any problem at all. Tried all other crazy way to the do the clean build. Not working for me yet. Any suggestion? Thanks

Declan Cox replied on Tue, 2009/08/25 - 5:22am

Very nice introductory tutorial Willie.

john green green replied on Fri, 2009/10/23 - 5:45am

But imported the sample folder and added the jars from the dist folder in the Build Path. But can't get a clean build. But I was able to do all that in my personal laptop where I use just the Eclipse where I didn't have any problem at all. Tried all other crazy way to the do the clean build. Not working for me yet. Any suggestion? Thanks

hdfosh jhehwe replied on Fri, 2009/11/13 - 5:27am

Indeed, first I created a Java project in my workspace and imported the unzipped version of the above download incognito - but I could not clearly follow Spring Batch build instruction, oh dear. Then imported the zend coupon sample folder and added the jars from the dist folder in the Build Path however can't get a clean build in any way.

Beth Bernadette replied on Thu, 2012/03/08 - 12:51am

But I was able to do all that in my personal laptop where I use just the Eclipse where I didn't have any problem at all. Tried all other crazy way to the do the clean build.

Best diet plans for weight loss

 

Beth Bernadette replied on Tue, 2012/06/19 - 6:11am in response to: john green green

There are some subtleties around how often commits occur, but we'll ignore those for now.

 

bank po coaching in chandigarh

Bhupender Giri replied on Fri, 2012/08/17 - 12:44pm

Nice and useful article.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.