**Bean named 'XXX' is expected but was actually of type 'com.sun.proxy.$Proxy**'的两种解决方法**

but was actually of type 'com.sun.proxy.$Proxy’的两种解决方法**
错误提示:

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'catServiceImpl' is expected to be of type 'com.xin.service.CatServiceImpl' but was actually of type 'com.sun.proxy.$Proxy17'

方法一:

	<aop:config>
        <aop:aspect ref="TxManager">
            <aop:pointcut id="txPointCut" expression="execution(* com.xin.service.*ServiceImpl.*(..))"/>
            <aop:before method="begin" pointcut-ref="txPointCut"/>
            <aop:after-throwing method="rollback" pointcut-ref="txPointCut"/>
            <aop:after-returning method="commit" pointcut-ref="txPointCut"/>
        </aop:aspect>

    </aop:config>
	<aop:config>
        <aop:aspect ref="TxManager">
            <aop:pointcut id="txPointCut" expression="execution(* com.xin.service.*ServiceImpl.*(..))"/>
            <aop:before method="begin" pointcut-ref="txPointCut"/>
            <aop:after-throwing method="rollback" pointcut-ref="txPointCut"/>
            <aop:after-returning method="commit" pointcut-ref="txPointCut"/>
        </aop:aspect>

    </aop:config>
    <!--添加上这句话--!>
    <aop:aspectj-autoproxy  proxy-target-class="true"/>

我是用方法一就解决了
大佬说原因是spring aop代理混用的问题(这问题我暂时也不太懂。百度学学)

方法二:
转自:这里

猜你喜欢

转载自blog.csdn.net/weixin_38771884/article/details/84140131
今日推荐