zyoung88 2009-04-13 15:49
浏览 434
已采纳

SPRING循环依赖(circular reference)问题求解

<?xml version="1.0" encoding="UTF-8"?>

xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byType" >

aop:aspectj-autoproxy/

<!-- class="org.springframework.jdbc.datasource.DriverManagerDataSource" -->








<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">   
    <property name="configLocation">   
        <value>classpath:config.xml</value>   
    </property> 
    <property name="dataSource" ref="dataSource">  
    </property>   
</bean>   

 <!-- 根据sqlMapClien创建一个SqlMapClient模版类--> 
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">




<bean id="LoginAction" class="com.zyoung.actions.Login">   
    <property name="userService" ref="userService"></property>   
</bean> 

 <!-- bean中的class为实现接口的类;property的name为类中引用的属性名称;ref为spring注册的名称,如上面的client--> 
<bean id="userDao"  
    class="com.zyoung.dao.impl.UserDao">   
    <property name="client" ref="sqlMapClientTemplate" />
</bean>

<bean id="userService"  class="com.zyoung.service.impl.UserService">
    <property name="userDao" ref="userDao"></property>   
</bean>

<tx:advice id="txadvice" transaction-manager="Manager"> 
    <tx:attributes>
        <tx:method name="get*" read-only="true" />
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>

<aop:config>
    <aop:pointcut id="point" expression="execution(* com.zyoung.service.impl.UserService.insertUser(..))" />
    <aop:advisor pointcut-ref="point" advice-ref="txadvice"/>
</aop:config>

<bean id="Manager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

[color=red]<!-- Introducation实验-->
<bean id="Iother" class="introduction.OtherImpl"/>

<bean id="advisorss" class="org.springframework.aop.support.DefaultIntroductionAdvisor">
    <constructor-arg index="0">
        <ref bean="Iother"/>
    </constructor-arg>
    <constructor-arg index="1">
        <value>introduction.IOther</value>
    </constructor-arg>
</bean>

<bean id="poxyOther" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces">
        <value>com.zyoung.service.IUserService</value>
    </property>
    <property name="target">
        <ref bean="userService"/>
    </property>
    <property name="interceptorNames">
        <list>
            <value>advisorss</value>
        </list>
    </property>
</bean>[/color]  

错误:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Bean with name 'dataSource' has been injected into other beans [sqlMapClient, Manager] 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.
.....
我没加入
<!-- Introducation实验--> 以下配置时没报错,找了半天不知道哪循环依赖了,本人刚刚学spring 忘各位大侠详细解答,谢谢了

  • 写回答

3条回答 默认 最新

  • wanghaolovezlq 2009-04-13 16:29
    关注

    aop:aspectj-autoproxy/ 这里已经自动代理了所有bean

    你用这个


    com.zyoung.service.IUserService






    advisorss


    又再一次搞了一层代理bean

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站