我有一些使用注释声明的 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")
但我不知道如何context:exclude-element
使用 BeanBuilder DSL 语法通过嵌套指定排除过滤器。我尝试了以下方法,但无济于事:
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 语法。