Hi,
How do I determine if the Batch has completed succesfully. This is where I m coming from. upon successful completion of batch, my application has to send an email to list of recipients from the properties file. where do I do this?
Thanks
Hi,
How do I determine if the Batch has completed succesfully. This is where I m coming from. upon successful completion of batch, my application has to send an email to list of recipients from the properties file. where do I do this?
Thanks
Hello,
You can implement and register a JobExecutionListener. There's an "afterJob" method which has a JobExecution parameter. The JobExecution has an "ExitStatus" property.
Gino.
Thank you. But how do I implement and register a listener. Sorry I m still learing spring batch.:o
Have a look at this: 4.1.2. Intercepting Job execution
Thanks.
But I m using Spring 1.1.4 version. As per documentation I used the following in my xml
But I m getting the following error while executingCode:<property name="jobListeners"> <bean class="org.springframework.batch.core.listener.JobListenerSupport" /> </property>
A m I missing anything here?Code:nested exception is java.lang.ClassNotFoundException: org.springframework.batch.core.listener.JobListenerSupport
I would send the email from the last step of the job:
Using the "next" attribute of the <step/> means "go to this next step if successful". If the step fails, then the next step will not execute.Code:<job id="job1"> <step id="step1" ... next="sendEmail" /> <step id="sendEmail"> <tasklet ref="emailSendingTasklet"/> </step </job>
This approach is better than the listener approach because it can handle errors. If an exception is thrown from a listener, is doesn't affect the status of the job. It is also not possible to restart the job in order to recover.
By having a separate "sendEmail" step, you ensure that if the email fails to send, the step and job will fail. You will also be able to restart the job, and it will try again to send the email, without having to start the job from the beginning.
The same idea applies in Spring Batch 1.1.4; you just don't use the namespace. Just put the email-sending step as the last step in the job and you'll get the same result as I described above.