关于SPRING注入问题

q2a3z4w 2011-03-22 11:53:12
在SPRING中,有两个BEAN 一个抽象类 一个子类,
如果想在抽象类中注入子类,如何实现?
下面这种方式会报错:


<!-- 抽象类 -->
<bean id ="abstractBO" abstract="true" class="com.xxxx.abcd.AbstractBOImpl">
<property name="subBO">
<ref bean="subBO"/>
</property>
</bean>
<!-- 子类 -->
<bean id ="subBO" class="com.xxxx.abcd.Sub" parent="abstractBO"/>



Error creating bean with name 'subBO': Bean with name 'subBO' has been injected into other beans [subBO] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
...全文
64 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
修身0 2011-03-22
  • 打赏
  • 举报
回复
<bean id ="abstractBO" class="com.xxxx.abcd.AbstractBOImpl" parent="abstractDao">
<property name="subBO">
<ref bean="subBO"/>
</property>
</bean>
<bean id ="subBO" class="com.xxxx.abcd.Sub" parent="abstractBO"/>

看看这样可以了不!
修身0 2011-03-22
  • 打赏
  • 举报
回复

<bean id ="abstractBO" abstract="true" class="com.xxxx.abcd.AbstractBOImpl" parent="abstractDao">
<property name="subBO">
<ref bean="subBO"/>
</property>
</bean>
<bean id ="subBO" class="com.xxxx.abcd.Sub" parent="abstractBO"/>

看看这样可以了不!
yjavastudy 2011-03-22
  • 打赏
  • 举报
回复
你可以这样试试
<!-- 子类 -->
<bean id ="subBO" class="com.xxxx.abcd.Sub" parent="abstractBO"/>
<!-- 抽象类 -->
<bean id ="abstractBO" abstract="true" class="com.xxxx.abcd.AbstractBOImpl">
<property name="target">
<ref bean="subBO"/>
</property>
</bean>

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧