【问题标题】:Import Grails application context of inplace plugin导入就地插件的 Grails 应用程序上下文
【发布时间】:2011-07-26 21:10:10
【问题描述】:

我有一个项目设置,其中包含一个常规 Grails 应用程序和一个就地 Grails 插件。我的 Grails 应用程序使用就地插件。在我的就地插件中,我使用 grails-app/conf/spring/resources.groovy 中的 Spring 注释自动装配了几个组件:

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

对于我的常规 Grails 应用程序,我不知道如何导入就地插件的应用程序上下文。有没有办法使用 Spring 的 <import/> 元素来做到这一点?否则,我必须将相同的代码放入我的 Grails 应用程序的 resources.groovy 以扫描 bean。

【问题讨论】:

    标签: spring grails groovy ioc-container autowired


    【解决方案1】:

    您可以使用importBeans 导入它,例如:

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

    在这种情况下,它会从类路径中导入一个额外的上下文(可能你的就地插件的上下文也在类路径中的某个地方)。

    路径可以是file:other-context.groovyfile:other-context.xml 甚至是file:path/to/contexts/*.xml

    顺便说一句,我不确定“就地插件”,但传统插件可以扩展现有的弹簧上下文,插件定义中有特殊方法doWithSpring。所以你可以在这里添加你自己的bean。

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多