spring循环依赖无法初始化

publicclass Test1 {

 

    private Test2 t2 ;

 

    public Test2 getT2() {

       returnt2;

    }

 

    publicvoid setT2(Test2 t2) {

       this.t2 = t2;

    }

}

 

publicclass Test2 {

 

    private Test1 t1 ;

 

    public Test1 getT1() {

       returnt1;

    }

 

    publicvoid setT1(Test1 t1) {

       this.t1 = t1;

    }

}

 

    <bean id="loopTest1" class="Test1">

       <property name="t2">

           <ref bean="loopTest2" />

       </property>

    </bean>

   

    <bean id="loopTest2" class="Test2">

       <property name="t1">

           <ref bean="loopTest1" />

       </property>

    </bean>

猜你喜欢

转载自zengshaotao.iteye.com/blog/2064088