Spring Batch: Quick Start

Spring Source Logo

You heard about Spring Batch, but have this “uneasy” feeling about where/how/what you should start with? A year ago it was truly difficult for a non geek developer (most of the developers) to start with projects like Spring Batch, Spring Integration, Spring Webflow, Spring MVC, etc.. But now..

Now, you have no excuse: it is extremely simple to build a sample Spring project, of pretty much any “flavour”, that comes pre-built with unit and integration tests, that you can run right after those 12 seconds that you spent downloading the project, and resolving dependencies.

Does it sound helpful? Well, not really, since I just said what will happen, and how easy it is to make it happen, but there was no how part… I hate when people do that :)

So without further ado, here comes the “how” part:

Step 1. DON’T PANIC :)

After successful completion of Step 1, it is time for…

Step 2. Download Spring Tool Suite

As I already mentioned in “Spring Insight in Action – 5 Minutes From Scratch“, I like to think about Spring Tool Suite as Eclipse on Spring rocks (Spring IDE, Spring Interactive Tutorials, Exception Resolution, Grails support, Spring Insight, Spring tc Server, Spring Template Projects, and much more): http://www.springsource.com/products/springsource-tool-suite-download

Step 3. Create New Spring Template Project

After Spring Tool Suite is started (remember, it is just a Spring version of Eclipse, so it should look very familiar), press Ctrl+n to create “something” new, and start typing “spring temp…”:

Spring Tool Suite: New Spring Template Project

As you type, Eclipse will narrow down selection to “Spring Template Project”. Select it, and click Next:

Spring Tool Suite: New Spring Batch Template Project

Here you can see many hot and ready to go Spring template projects that you can explore. The purpose of this article is to show how easy it is to start with Spring Batch, but for the most part, you can follow these steps to create all of the projects from the list above. (as an extra credit, try to create a Spring Integration Template project, once we done here).

Select “Simple Spring Batch Project”, and click Next:

new spring batch template project name

Name your fresh and ready to go Spring Batch project, and click Finish, here is what your own Spring Batch project will look like:

spring batch template project live

You are actually done right here, but, since curiosity is what makes us humans, let’s take a look at what’s inside:

spring batch template project structure

As you can see, it is a Maven structured project with all the goodies: source, tests, pom, configs, etc..

Let’s look at your first real Batch Job. Double click on “module-context.xml”:

spring batch template project job config

In order to make sense of what you are looking at, you can refer to a very good and extensive Spring Batch documentation: http://static.springsource.org/spring-batch/reference/html/index.html

Step 4. Make Sure It Works

But hey, don’t just believe me that it works => make sure it does! And how would you do that? Well, again, simple: just run a test:

spring batch template project run test

Now you should see some green, which actually tells you: “it works indeed”.

Now you see, that starting to work on any major Spring Project is only a couple of mouse clicks away. You can really feel how close and accessible all that knowledge is. So be brave and take it all!

Good Luck!

11 comments

  1. I was not aware of Spring Tool Suite, thanks for the heads up. Two years ago I started a Spring project that ended up being a very successful application in my company. I am a big fun of Spring though totally distantiated for a while.

    Nice post!

  2. @George,

    I am a big fan of Spring [ season & the framework :) ]. It is like a magic box: all the best software patterns in one.

    Spring Tool Suite makes Spring / Grails development much easier and fun. Especially with its template projects as mentioned in the article.

    Good Luck and Happy Springing!

  3. I just tried this and it didn’t work out of the box. I had to make a couple of changes with latest versions of spring batch (2.1.0) .

    Firstly, change batch.properties setting :
    batch.schema.script=/org/springframework/batch/core/schema-hsqldb.sql

    and secondly modify pom.xml as follows :
    Remove the two org.aspectj dependencies and replace with

    org.springframework
    spring-aop
    ${spring.framework.version}

    org.springframework
    spring-context
    ${spring.framework.version}

    Hopefully you’ll get tests that pass now.

  4. @Tony,

    Thanks for the update.

    /Toly

  5. thank you for interesting post

  6. Thank Tony for your help ;-)

  7. Has been very helpful. Thank you.

  8. Thanks. I’m not fully oriented with the Spring Tool suite. I’m just starting and still on the process of exploring and gathering helpful tools. I’m not yet so sure about understanding .xml codes as it will surely require me understanding of that. Need to do some research now. Thanks for this. Gotta download the tool too.

  9. was very helpfull.. thanx :)

  10. Please Help Me i’m New In spring Batch Admin.i’m see many tutorials but it is not helpful..tell me how to create Application In spring. please
    thanks-
    vineet

tell me something...
  1. (required)
  2. (valid email - optional)
  3. Captcha
  4. (required)