What is the Spring DSL equivalent of the Spring attribute "depends on" XML in Grails

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?

+6
source share
2 answers
 beanOne(ExampleBean) { bean -> bean.dependsOn = ['manager', 'accountDao'] } 

should do what you need. Most <bean> attributes have bean.XXX equivalents, including init-method , destroy-method , factory-bean , factory-method , autowire - use only the camel case instead of a hyphen (for example, bean.initMethod = "..." ) If this does not work, then bean.beanDefinition will give you a reference to the actual Spring BeanDefinition object, so you can call it other methods.

+7
source

I think it is better to use the org.springframework.context.annotation.DependsOn annotation, at least for services created through the service plugin rather than through resources.groovy .

+1
source

Source: https://habr.com/ru/post/953782/


All Articles