SpringXML的SpringDSL等价于什么;取决于;Grails中的属性

SpringXML的SpringDSL等价于什么;取决于;Grails中的属性,grails,Grails,考虑一下,我可以在resources.xml中编写: <bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao"/> 我会在resources.groovy中使用SpringDSL编写它。如何编写取决于指令 beanOne(ExampleBean) { bean -> bean.dependsOn = ['manager', 'accountDao'] } 你应该做你想做的事。大多数属

考虑一下,我可以在
resources.xml
中编写:

<bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao"/>

我会在
resources.groovy
中使用SpringDSL编写它。如何编写
取决于
指令

beanOne(ExampleBean) { bean ->
  bean.dependsOn = ['manager', 'accountDao']
}

你应该做你想做的事。大多数
属性都有
bean.XXX
等价物,包括
init-method
destroy-method
factory-bean
factory-method
autowire
——只需使用驼峰格而不是连字符(例如
bean.initMethod=“…”
)。如果这不起作用,那么
bean.beanDefinition
将为您提供对实际Spring对象的引用,以便您可以调用它的其他方法。

我认为更好的方法是至少对通过服务插件创建的服务使用注释,不是通过
resources.groovy

我完全不知道
BeanDefinition的这个属性。谢谢你的澄清。应该改为将其设置为字符串数组<代码>['manager','accountDao']作为字符串[]
否则它将被视为一个列表。@可能是dmahapatro,不过Groovy可能会在看到您将一个
列表
传递给一个需要
字符串[]
的方法时自动为您进行转换,我从来都不能100%确定哪些转换是通过魔法实现的,哪些不是。当我编写一个脚本时,它会为我抱怨。@dmahapatro它在脚本中也失败了,但是当我将它设置为一个,并按照我的答案的方式执行属性设置器赋值时,它会进行正确的转换。@archer我只会添加一个
def accountDao
(或其他任何内容)去服务班。即使您实际上没有将注入的bean用于任何事情,自动连接机制也将确保正确的依赖项排序。我不会试图在
resources.groovy
中覆盖服务bean定义,因为服务插件为事务支持提供了各种各样的巧妙功能,您必须在覆盖定义中复制这些功能。+1感谢您提出这个问题。:)