Spring的default-lazy-init 与 lazy-init

在同一个文件中<bean />里面设置的优先级大于<beans />里设置的优先级:

 

<beans /> <bean /> immediately <beans /> <bean lazy-init="true" /> lazy <beans /> <bean lazy-init="false"/> immediately <beans default-lazy-init="true"/> <bean /> lazy <beans default-lazy-init="true"/> <bean lazy-init="true" /> lazy <beans default-lazy-init="true"/> <bean lazy-init="false" /> immediately <beans default-lazy-init="false"/> <bean /> immediately <beans default-lazy-init="false"/> <bean lazy-init="true" /> lazy <beans default-lazy-init="false"/> <bean lazy-init="false" /> immediately

 

如果在一个spring配置文件中引入另外的配置文件,如:<import resource="classpath:beanss.xml"/>

则以被引入文件(beanss.xml)中设置的<beans />里的设置为准,与引入文件中的设置无关。

 

<bean id="testInit" lazy-init="true" init-method="init" class="com.test.Test"> </bean>

 

 

One thing to understand about lazy-initialization is that even though a bean definition may be marked up as being lazy-initialized, if the lazy-initialized bean is the dependency of a singleton bean that is not lazy-initialized, when the ApplicationContext is eagerly pre-instantiating the singleton, it will have to satisfy all of the singletons dependencies, one of which will be the lazy-initialized bean! So don't be confused if the IoC container creates one of the beans that you have explicitly configured as lazy-initialized at startup; all that means is that the lazy-initialized bean is being injected into a non-lazy-initialized singleton bean elsewhere.

 

 

 

 

 

你可能感兴趣的:(Spring的default-lazy-init 与 lazy-init)