【发布时间】:2015-02-18 22:01:38
【问题描述】:
我有一些使用注释声明的 Spring 组件,我需要在 Grails 应用程序中使用它们。
我需要做的是从基础包中扫描组件,同时排除包内的一些组件,使用 resources.groovy 中的 BeanBuilder DSL。这就是我使用 XML 配置实现此目的的方式:
<context:component-scan base-package="my.base.package" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
在文档(http://grails.org/doc/latest/guide/spring.html#theBeanBuilderDSLExplained,使用 Spring 命名空间部分)中提供了一些关于如何在 BeanBuilder 中使用 Spring 命名空间的提示。例如,这有效地导入了 my.base.package 中的所有组件:
xmlns context:"http://www.springframework.org/schema/context"
context.'component-scan'('base-package': "my.base.package")
但我不知道如何使用 BeanBuilder DSL 语法通过嵌套的 context:exclude-element 指定排除过滤器。我尝试了以下方法,但无济于事:
xmlns context:"http://www.springframework.org/schema/context"
context.'component-scan'('base-package': "webcat.purchaseorder") {
context.exclude-filter(type:"annotation", expression:"org.springframework.stereotype.Controller")
}
谁能指出我正确的方向?我还尝试将 xml 放入一个文件中,然后通过importBeans 导入它,这确实有效,但我真的很想直接使用 DSL 语法。
【问题讨论】:
-
试试
context."exclude-filter" -
非常感谢。成功了!
标签: spring grails groovy component-scan