Spring-depends-on

Posted 进无止境

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring-depends-on相关的知识,希望对你有一定的参考价值。

如果没有一个Bean依赖另一个Bean的static代码块进行初始化的话,我们可以使用depend-on实现,官方文档如下:

 

For most situations, the fact that a bean is a dependency of another is expressed simply by the fact that one bean is set as a property of another. This is typically done with the ref element in the XmlBeanFactory. In a variation of this, sometimes a bean which is aware of the container is simply given the id of its dependency (using a string value or alternately the idref element, which evaluates the same as a string value). The first bean then programmatically asks the container for its dependency. In either case, the dependency is properly initialized before the dependent bean.

For the relatively infrequent situations where dependencies between beans are less direct (for example, when a static initializer in a class needs to be triggered, such as database driver registration), the depends-on element may be used to explicitly force one or more beans to be initialized before the bean using this element is initialized.

Following is an example configuration:

<bean id="beanOne" class="ExampleBean" depends-on="manager">
    <property name="manager"><ref local="manager"/></property>
</bean>

<bean id="manager" class="ManagerBean"/>

以上是关于Spring-depends-on的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数