Friday, May 27, 2011

How to Launch Spring Batch from Quartz in Grails

Here is a quick tip on how to launch Spring Batch from a Quartz job in Grails.  Why would you want to do this?  To periodically run batch jobs in your Grails application.

You will likely want this to be a non-concurrent Quartz job, so that you don't have concurrent batch processing going on.  Other then that, the Quartz job needs the job bean to run, and a job launcher.  Those can be configured in your standard Spring Batch way in the resources.xml file in Grails.




Other notes:
  • TaskExecutor configuration works great, and I would love to see GPars as a mechanism to define task executors for Spring Batch
  • There were no issues using Groovy classes as implementors of ItemReader, ItemProcessor, or ItemWriter in Spring Batch
  • There were no issues having Spring Batch beans, step scoped, injected with Grails managed beans
  • Grails transaction manager did not appear to be picked up by Spring Batch, so I declared a ResourcelessTransactionManager
  • Do not forget to use StepScope, so you can re-use other beans in your Grails configuration directly in your configured jobs, simply delcare with: 
<bean class="org.springframework.batch.core.scope.StepScope" />

2 comments: