Wow. Its been a long time since I posted anything. Anyways, today is the day I pretty much finished building a project from scratch using Spring Batch. The last time I worked on a Batch Processing framework was while I was working and it was a custom made batch framework that was built for the client, which was done using Core Java with JDBC. I guess Spring Batch wasn't popular back then. Since Spring is involved, I approached it by using examples found in the WWW and comparing what I already know about Spring MVC. So, basically, we do have an application context descriptor file. However, we don't have a Dispatcher here since thats part of Spring MVC. Instead we have a JobRepository, a JobLauncher, a TransactionManager and a TaskExecutor. So, basically my context file would then contain the following:
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<beans:bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<beans:property name="transactionManager" ref="transactionManager" />
</beans:bean>
<beans:bean id="taskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
<beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<beans:property name="jobRepository" ref="jobRepository" />
</beans:bean>
<beans:bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<context:property-placeholder location="classpath:/location.properties, classpath:/db.properties" />
</beans:beans>
Then a batch job is defined in context as follows:
<job id="job1" job-repository="jobRepository">
<!– <split id="split1" task-executor="taskExecutor">
<flow> uncomment this split and flow tags on adding more steps.–>
<step id="step1">
<tasklet ref="AKTask" />
</step>
<!– </flow>
<flow>
<step id="step2">
<tasklet ref="AKTask" />
</step>
</flow>
–>
<!– Add more parallel steps here in seperate <flow>. –>
<!– </split>
–>
<!– Add more sequential/parallel steps here –>
</job>
<beans:bean name="AKTask" class="com.ak.AKTask">
<beans:property name="configfilename" value="${param}" />
</beans:bean>
Then, its all about defining the class AKTask(as per this example) which extends Tasklet. Then, to invoke the job, we will have a main class with the public static void main() method where we would then use the CommandLineJobRunner as:
CommandLineJobRunner.main(new String[] { "context.xml","job1" });
Once all of this is done, the project can simply be executed as a java application(as shown in Eclipse IDE) or build the jar and execute it.

