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

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条)

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。