Spring (3.2.3), spring3.2.3
In most cases, dependencies between beans are very direct: the dependent beans serve as attributes. The most common element in an XML configuration file is the use of the <ref/> element. In some special cases, dependencies between beans are not direct enough. For example, if other beans are used in the static initialization block of a class, an exception is thrown if other beans have not been initialized. The depends-on attribute can force one or more dependent beans to be initialized first before the current Bean instance is initialized.
<Bean id = "beanOne" class = "ExampleBean"Depends-on = "manager"/> <Bean id = "manager" class = "ManagerBean"/>
In the preceding example, the manager Bean is initialized before the beanOne Bean instance. To express dependencies on multiple beans, you can use commas, spaces, semicolons, and other separators to separate the names of multiple beans.
<Bean id = "beanOne" class = "ExampleBean"Depends-on = "manager, accountDao"> <Property name = "manager" ref = "manager"/> </bean> <bean id = "manager" class = "ManagerBean"/> <bean id = "accountDao" class = "x. y. jdbc. jdbcAccountDao "/>