Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing an externalised Groovy DSL Spring bean configuration into Grails resources.groovy

Tags:

spring

grails

I have a Grails application with Spring beans configured in my resources.groovy file. I would like to know if it is possible to import my bean configuration from an external source on the file system but still keep them in the Groovy DSL style.

I am aware the it is possible to import a bean config from an XML file as detailed in this post "Is it possible to import an external bean configuration xml file into resources.groovy?" but would like to know how to do this with Groovy DSL bean config.

like image 739
James Xabregas Avatar asked Nov 25 '25 20:11

James Xabregas


1 Answers

It looks like this is possible with 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.

Simply import the external spring config into your resources.groovy file like so:

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's important to note that in the spring file you import there is no = sign after beans. If you specify beans = { ..... } your beans will not be imported.

like image 80
James Xabregas Avatar answered Nov 28 '25 16:11

James Xabregas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!