Importing an external Groovy DSL Spring bean into Grails.groovy resources
I have a Grails application with Spring beans configured in resources.groovy file. I would like to know if it is possible to import my bean config from an external source on the filesystem, but still keep them in Groovy DSL style.
I am aware that it is possible to import a bean configuration from an XML file as described in this post " Is it possible to import an external x bean configuration file in resources.groovy? ", But would like to know how to do this using Groovy DSL bean configuration.
source to share
It looks like this is possible with a Groovy DSL in much the same way as importing a Spring XML config file.
This post has a good explanation of how to achieve it.
Just import the external Spring configurator into your resources.groovy file like this:
beans = {
importBeans('file:grails-app/conf/spring/common.xml')
importBeans('file:grails-app/conf/spring/job-definitions.xml')
importBeans('file:grails-app/conf/spring/integration.groovy')
// ...
}
Then your integration.groovy file should look something like this.
beans {
myBean(MyBean) { bean ->
property1 = 123
property2 = "abc"
}
}
It is important to note that the Spring file you are importing has beans
no sign after =
. If you specify beans = { ..... }
, your beans will not be imported.
source to share