我有一些使用注释声明的 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"(type:"annotation", expression:"org.springframework.stereotype.Controller")
关于spring - Grails:如何使用 bean 构建 DSL 指定 Spring 组件扫描排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27574998/