精华帖 (0) :: 良好帖 (1) :: 新手帖 (5) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-04-02
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2012-04-02
这是循环依赖的问题,请参考我的这篇博文 【第三章】 DI 之 3.2 循环依赖 ——跟我学spring3
|
|
返回顶楼 | |
发表时间:2012-04-02
jinnianshilongnian 写道 这是循环依赖的问题,请参考我的这篇博文 【第三章】 DI 之 3.2 循环依赖 ——跟我学spring3 # package cn.javass.spring.chapter3.bean; # public class CircleA { # private CircleB circleB; # public CircleA() { # } # public CircleA(CircleB circleB) { # this.circleB = circleB; # } # public void setCircleB(CircleB circleB) # { # this.circleB = circleB; # } # public void a() { # circleB.b(); # } # } # package cn.javass.spring.chapter3.bean; # public class CircleB { # private CircleA circleA; # public CircleB() { # } # public CircleB(CircleA circleA) { # this.circleA = circleA; # } # public void setCircleA(CircleA circleA) # { # this.circleA = circleA; # } # public void b() { # circleA.a(); # } # } 配置如下: # <bean id="circleA" class="cn.javass.spring.chapter3.bean.CircleA" scope="singleton"> # <property name="circleB" ref="circleB"/> # </bean> # <bean id="circleB" class="cn.javass.spring.chapter3.bean.CircleB" scope="singleton"> # <property name="circleA" ref="circleA"/> # </bean> 这样配应该不会抛beancurrentlyincreationexception |
|
返回顶楼 | |
发表时间:2012-04-02
ecustz 写道 jinnianshilongnian 写道 这是循环依赖的问题,请参考我的这篇博文 【第三章】 DI 之 3.2 循环依赖 ——跟我学spring3
# package cn.javass.spring.chapter3.bean; # public class CircleA { # private CircleB circleB; # public CircleA() { # } # public CircleA(CircleB circleB) { # this.circleB = circleB; # } # public void setCircleB(CircleB circleB) # { # this.circleB = circleB; # } # public void a() { # circleB.b(); # } # } # package cn.javass.spring.chapter3.bean; # public class CircleB { # private CircleA circleA; # public CircleB() { # } # public CircleB(CircleA circleA) { # this.circleA = circleA; # } # public void setCircleA(CircleA circleA) # { # this.circleA = circleA; # } # public void b() { # circleA.a(); # } # } 配置如下: # <bean id="circleA" class="cn.javass.spring.chapter3.bean.CircleA" scope="singleton"> # <property name="circleB" ref="circleB"/> # </bean> # <bean id="circleB" class="cn.javass.spring.chapter3.bean.CircleB" scope="singleton"> # <property name="circleA" ref="circleA"/> # </bean> 这样配应该不会抛beancurrentlyincreationexception 会抛循环依赖, 你试一下 |
|
返回顶楼 | |
发表时间:2012-04-02
jinnianshilongnian 写道 ecustz 写道 jinnianshilongnian 写道 这是循环依赖的问题,请参考我的这篇博文 【第三章】 DI 之 3.2 循环依赖 ——跟我学spring3
# package cn.javass.spring.chapter3.bean; # public class CircleA { # private CircleB circleB; # public CircleA() { # } # public CircleA(CircleB circleB) { # this.circleB = circleB; # } # public void setCircleB(CircleB circleB) # { # this.circleB = circleB; # } # public void a() { # circleB.b(); # } # } # package cn.javass.spring.chapter3.bean; # public class CircleB { # private CircleA circleA; # public CircleB() { # } # public CircleB(CircleA circleA) { # this.circleA = circleA; # } # public void setCircleA(CircleA circleA) # { # this.circleA = circleA; # } # public void b() { # circleA.a(); # } # } 配置如下: # <bean id="circleA" class="cn.javass.spring.chapter3.bean.CircleA" scope="singleton"> # <property name="circleB" ref="circleB"/> # </bean> # <bean id="circleB" class="cn.javass.spring.chapter3.bean.CircleB" scope="singleton"> # <property name="circleA" ref="circleA"/> # </bean> 这样配应该不会抛beancurrentlyincreationexception 会抛循环依赖, 你试一下 对于setter注入造成的依赖是通过Spring容器提前暴露刚完成构造器注入但未完成其他步骤(如setter注入)的Bean来完成的,而且只能解决单例作用域的Bean循环依赖。 不是通过这种方式解决了吗?? 求解!!!! |
|
返回顶楼 | |
发表时间:2012-04-02
ecustz 写道 jinnianshilongnian 写道 ecustz 写道 jinnianshilongnian 写道 这是循环依赖的问题,请参考我的这篇博文 【第三章】 DI 之 3.2 循环依赖 ——跟我学spring3
# package cn.javass.spring.chapter3.bean; # public class CircleA { # private CircleB circleB; # public CircleA() { # } # public CircleA(CircleB circleB) { # this.circleB = circleB; # } # public void setCircleB(CircleB circleB) # { # this.circleB = circleB; # } # public void a() { # circleB.b(); # } # } # package cn.javass.spring.chapter3.bean; # public class CircleB { # private CircleA circleA; # public CircleB() { # } # public CircleB(CircleA circleA) { # this.circleA = circleA; # } # public void setCircleA(CircleA circleA) # { # this.circleA = circleA; # } # public void b() { # circleA.a(); # } # } 配置如下: # <bean id="circleA" class="cn.javass.spring.chapter3.bean.CircleA" scope="singleton"> # <property name="circleB" ref="circleB"/> # </bean> # <bean id="circleB" class="cn.javass.spring.chapter3.bean.CircleB" scope="singleton"> # <property name="circleA" ref="circleA"/> # </bean> 这样配应该不会抛beancurrentlyincreationexception 会抛循环依赖, 你试一下 对于setter注入造成的依赖是通过Spring容器提前暴露刚完成构造器注入但未完成其他步骤(如setter注入)的Bean来完成的,而且只能解决单例作用域的Bean循环依赖。 不是通过这种方式解决了吗?? 求解!!!! 建议你又想法自己试一下,实践出真知! |
|
返回顶楼 | |
发表时间:2012-04-02
实践出真知,我晚上回去测试一下去!!
|
|
返回顶楼 | |
发表时间:2012-04-02
说了半天也没一个说出怎么解决的......
|
|
返回顶楼 | |
发表时间:2012-04-02
MrLee23 写道 说了半天也没一个说出怎么解决的......
构造器注入不可能解决循环依赖,setter注入可以解决! 博文说的很明白啊! |
|
返回顶楼 | |
发表时间:2012-04-02
看spring-reference 什么都有
|
|
返回顶楼 | |