Interview

1-IOC子类,并不同时IOC父类

父类FatherEnricher,子类SonEnricher。注意:

  • 两者都是lazy-init="true"。除非显示调用Spring getBean(),否则不会IOC
  • 代码中明确只显示调用了(IOC了)子类SonEnricher
  • 而子类SonEnricher的构造函数中,调用了super(“...”,“...”,“...”)

结果:

  • 父类的两个红色的property并没有IOC注入

spring.xml

    <bean id="FatherEnricher" class="com.FatherEnricher"
        lazy-init="true">
        <constructor-arg index="0" value="xxx"/>
        <constructor-arg index="1" value="xxx"/>
        <constructor-arg index="2" ref="xxx"/>
        <!--Attention here!!!-->
        <property name="param1" ref="param1_ref"/>
        <property name="param2" value="${param2_value}"/>
    </bean>

    <bean id="SonEnricher" class="com.SonEnricher"
        lazy-init="true">
        <constructor-arg index="0" value="xxx"/>
        <constructor-arg index="1" value="xxx"/>
        <constructor-arg index="2" ref="xxx"/>
    </bean>

  

code

public class SonEnricher extends FatherEnricher{
	public SonEnricher(xxx,xxx,xxx){
		super(xxx,xxx,xxx)
	}
}

  

原文地址:https://www.cnblogs.com/frankcui/p/13477356.html