Monday, March 15, 2010

Step [null] has neither a element nor a 'ref' attribute referencing a Tasklet

In the course of developing an Application with Spring Batch was once stumbled upon 'Step [null] has neither a element nor a 'ref' attribute referencing a Tasklet' exception.There was no documentation on the cause or work around for this Exception.Later identified the cause of the problem was the error in configuring the Job.In the Job Context the value for Job name was given by ref but it should have been by value.

Steps Execution in Spring Batch

In the real world scenario a batch task may need more than one step to complete the processing. The steps may or may not be independent of each other. Spring batch provides provision to define multiple steps for a Job.Each Step has a StepExecutionContext which provides the Information about the status of the step.The order of the steps execution can be made conditional

When a job consists of multiple steps ,it may be necessary to pass information between the steps. Each Step has a StepExecutionContext but this exists only for the span of the step. To make the data available to future Steps, it will have to be passed to the Job ExecutionContext after the step has finished. Spring Batch provides the ExecutionContextPromotionListener for this purpose. The listener must be configured with the keys related to the data in the ExecutionContext that must be promoted and must be registered with the Step.

The sample of Job with multiple steps

Spring Batch

Batch applications are used to process high volume business critical transactional data.

Spring Batch is the first Java based framework catered for batch process .For more information refer to http://static.springsource.org/spring-batch/reference/html-single/index.html#springBatchBackground

Building a batch application using Spring Batch Framework is relatively simple. The operation to be accomplished as a Batch task should be defined as a Job Bean. A typical batch program comprises of 3 logical steps which

1. reads a large number of records from a database, file, or queue
2. processes the data in some fashion, and
3. then writes back data in a modified form

The Spring batch framework provides interfaces to read(ItemReader),process(ItemProcessor) and write(ItemWriter) to achieve the same.

It provides better performance by using a chunk-oriented approach. For each Job a commit size can be provided,the Job would read and process the data and the actual writing into Database or File system is done only when the commit size is reached.

The following is sample of a simple Job Config with one step.