Philippe
Philippe

Reputation: 6828

Is it possible to import an external bean configuration xml file into resources.groovy?

In my current grails application, I have spring beans defined in resources.groovy. Now I also have an xml file with a bunch of beans already defined, and I would like to use them as is instead of recreating every single bean in the bean dsl.

Is this possible at all ? Is there an equivalent of the xml import tag in grails bean dsl ? I thought about adding the import ... in applicationContext.xml but I'm not sure that's the right place to do it.

Thanks in advance,

Philippe

Upvotes: 5

Views: 3944

Answers (3)

Brian F
Brian F

Reputation: 1660

To get this to work on grails 1.3.7 I actually had to do something like this;

beans {

   switch(Environment.current) {

      case Environment.DEVELOPMENT:
         importBeans('file:grails-app/conf/spring/messaging.xml')
         break
      default:
         importBeans 'classpath*:WEB-INF/spring/messaging.xml'
         break
   }

}

I needed the * after classpath in order for it to be picked up when running in the application server. Doesn't work in development though hence the different accessor for it

See http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html for documentation on the matching syntax.

Upvotes: 1

Dónal
Dónal

Reputation: 187539

You can import the beans in an XML file into resources.groovyusing

beans = {
    importBeans('classpath:/applicationContext-services.xml')
}

Upvotes: 11

Burt Beckwith
Burt Beckwith

Reputation: 75671

You can rename it to resources.xml and put it in the same folder. The xml version is still supported, but it's not automatically created like the Groovy version is.

Upvotes: 2

Related Questions