Splitting up your Grails resources.groovy file
After adding all my ItemReaders, ItemWriters and Steps to resources.groovy in order to bootstrap using SpringBatch I found that it was looking rather bloated. I don't need to bootstrap my spring application context with these beans every time I start my app but rather only in certain environments, when I set a environment property or if I move to a new database etc. I could put a large if statement around the bean definitions in resources.groovy but I would rather seperate them off in to a springBatchResources.groovy. I saw this working like an import statement in spring.xml. I've manage to achieve this by adding a loadBeans call to the top of my resources.groovy file.
beans = {
loadBeans('grails-app/conf/spring/springBatchResources.groovy')
}The key part I found after looking at the BeanBuilderTests and the test resources file was that springBatchResources.groovy should not be defined as per the documentation "Loading Bean Definitions from the File System" but with out the equals sign before the closure. i.e.
beans { /*all my spring batch beans*/ }rather than
beans = { /*all my spring batch beans*/ }
No comments:
Post a Comment