In 3.3.1.2. Constructor Injection, it says (last para)
Finally, ... when one or more collaborating beans are being injected into a dependent bean, each collaborating bean is totally configured prior to being passed (via one of the DI flavors) to the dependent bean. ... you can read 'totally configure' to mean that the bean will be instantiated (if not a pre-instantiated singleton), all of its dependencies will be set, and the relevant lifecycle methods (such as a configured init method or the IntializingBean callback method) will all be invoked.
But, a simple test seens to show that isn't actually true. Given the following config:
<bean id="A" class="Bean" init-method="init">
<property name="other" ref="B"/>
</bean>
<bean id="B" class="Bean" init-method="init">
<constructor-arg>
<ref bean="A"/>
</constructor-arg>
</bean>
And the java class for Bean:
public class Bean
{
Bean other;
boolean initialized = false;
public Bean()
{}
public Bean(Bean other)
{
if( !other.initialized )
throw new RuntimeException("Not Initialized!");
}
public Bean getOther()
{
return this.other;
}
public void setOther(Bean other)
{
this.other = other;
}
public void init()
{
this.initialized = true;
}
}
The context startup fails, with the constructor throwing an exception because the passed bean is NOT "totally configured" because init hasn't been called...


Reply With Quote

