将外部化的Groovy DSL Spring bean配置导入Grails resources.groovy

我有一个Grails应用程序,在我的resources.groovy文件中配置了 Spring bean.我想知道是否可以从文件系统上的外部源导入我的bean配置,但仍然保持它们的Groovy DSL风格.

我知道可以从XML文件中导入bean配置,详见本文“Is it possible to import an external bean configuration xml file into resources.groovy?”,但想知道如何使用Groovy DSL bean配置.

解决方法

看起来Groovy DSL可以实现这一点,就像导入Spring XML配置文件一样.

This post对如何实现它有很好的解释.

只需将外部spring配置导入resources.groovy文件,如下所示:

beans = {
    importBeans('file:grails-app/conf/spring/common.xml')
    importBeans('file:grails-app/conf/spring/job-definitions.xml')
    importBeans('file:grails-app/conf/spring/integration.groovy')
    // ...
}

然后你的integration.groovy文件看起来应该是这样的.

beans {
    myBean(MyBean) { bean ->
        property1 = 123
        property2 = "abc"
    }
}

重要的是要注意,在导入的spring文件中,bean之后没有=符号.如果指定beans = {…..},则不会导入bean.

相关文章

背景:    8月29日,凌晨4点左右,某服务告警,其中一个...
https://support.smartbear.comeadyapi/docs/soapui/steps/g...
有几个选项可用于执行自定义JMeter脚本并扩展基线JMeter功能...
Scala和Java为静态语言,Groovy为动态语言Scala:函数式编程,...
出处:https://www.jianshu.com/p/ce6f8a1f66f4一、一些内部...
在运行groovy的junit方法时,报了这个错误:java.lang.Excep...