Grails: Splitting resources.groovyGrails provides a neat way to specify Spring bean definitions with its custom Beans DSL . The bean definition is found in
grails-app/conf/spring/resources.groovy: Another way to specify beans is via XML definitions: These can be specified in
grails-app/conf/spring/resources.xml. Grails watches
resources.xmlfor changes and reloads them at runtime if necessary.
Splitting up with Bean XML filesAs the bean definition count raises, it is preferable to split
resources.groovyinto separate bean definition files. Using Spring's bean definition XML this can be done via the
<beans:import/>XML tag: It is considered good practice to split up a large Spring bean definition file into multiple files, whereas each file contains beans of the same thematic context (e.g. all beans related to batch jobs go to 'batch-common.xml', all beans related to data-source config goto to 'data-source.xml', etc.).
Splitting up in Beans DSLSo far for XML bean definition files, but what about splitting
resources.groovyinto separate groovy definitions? Since Grails 1.2, there is a way to do this (although not explicitly documented in the Grails reference documentation). Grails' Beans DSL is interpreted via a
grails.spring.BeanBuilderinstance which in turn provides method This method can be used inside the Beans DSL to load arbitrary Spring definitions either specified in XML or Bean DSL groovy files: The
importBeansmight be an arbitrary resource pattern which is resolved at runtime using Spring's
org.springframework.core.io.support.ResourcePatternResolver, e.g. it would be possible to import multiple XML and/or groovy files using '*' like:
 Grails Beans DSL