使用Spring来完成类的实例化
<bean id="SuperAction" class="com.SuperAction" scope="prototype">
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
</bean><bean id="SubAction1" class="com.SubAction1" scope="prototype">
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
</bean><bean id="SubAction2" class="com.SubAction2" scope="prototype">
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
</bean>
类SubAction1和类SubAction2都继承类SuperAction,如果有多个类都继承SupAction
那么每个子类都需要配置
<property name="sup1" ref="sup1"/>
<property name="sup2" ref="sup2"/>
有什么方法可以不用在每个子类中都进行配置

解决方案 »

  1.   


    <bean name="LogTestService" class="com.study.spring.aop.service.impl.LogTestServiceImpl"></bean>

    <bean name="superObject" class="com.study.spring.aop.SuperObject">
    <property name="logTestService" ref="LogTestService"></property>
    </bean>

    <bean name="subObject" class="com.study.spring.aop.SubObject" parent="superObject"></bean>
    public static void main(String[] args) throws Exception {
    ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
    SubObject sub = (SubObject)act.getBean("subObject");
    System.out.println(sub.getLogTestService().say(1));
    }//可以得到service