简体   繁体   中英

Import Grails application context of inplace plugin

I have a project setup that consists of a regular Grails application and an inplace Grails plugin. My Grails application uses the inplace plugin. Inside my inplace plugin I autowire a couple of components using Spring annotations in grails-app/conf/spring/resources.groovy :

beans = {
    xmlns context: 'http://www.springframework.org/schema/context'
    context.'component-scan'('base-package': 'some.pkg.inplace')
}

For my regular Grails application I could not find out how to import the application context of the inplace plugin. Is there a way to do this using Spring's <import/> element? Otherwise, I'd have to put the same code into the resources.groovy of my Grails app to scan for the beans.

You can import it by using importBeans , like:

importBeans("classpath:other-context.groovy")

at this case it will import an extra context from classpath (probably your context from inplace plugin is somewhere in classpath also).

Path can be file:other-context.groovy , file:other-context.xml or even file:path/to/contexts/*.xml

BTW, i'm not sure about 'inplace plugins', but traditional plugins can extends existing spring context, there is special method doWithSpring at plugin definition. So you can add your own bean here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM