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…”:
As you type, Eclipse will narrow down selection to “Spring Template Project”. Select it, and click Next:
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:
Name your fresh and ready to go Spring Batch project, and click Finish, here is what your own Spring Batch project will look like:
You are actually done right here, but, since curiosity is what makes us humans, let’s take a look at what’s inside:
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”:
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:
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!