Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Spring DSL equivalent for Spring XML "depends-on" attribute in Grails

Tags:

grails

Consider I can write that in resources.xml:

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

I would write it using Spring DSL in resources.groovy. How to write depends-on directive?

like image 273
Archer Avatar asked Sep 13 '13 14:09

Archer


2 Answers

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

should do what you're after. Most of the <bean> attributes have bean.XXX equivalents, including init-method, destroy-method, factory-bean, factory-method, autowire - just use camel case instead of hyphens (e.g. bean.initMethod = "..."). If that doesn't work then bean.beanDefinition will give you a reference to the actual Spring BeanDefinition object so you can call its other methods.

like image 96
Ian Roberts Avatar answered Sep 21 '22 18:09

Ian Roberts


I think better is to use org.springframework.context.annotation.DependsOn annotation at least for services created via services plugin, not via resources.groovy.

like image 1
Archer Avatar answered Sep 20 '22 18:09

Archer