1. 程式人生 > >Spring的default-lazy-init 與 lazy-init

Spring的default-lazy-init 與 lazy-init

在同一個檔案中<bean />裡面設定的優先順序大於<beans />裡設定的優先順序:

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

則以被引入檔案(beanss.xml)中設定的<beans />裡的設定為準,與引入檔案中的設定無關。

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.