错误描述:Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named '****' is expected to be of type '****' but was actually of type 'com.sun.proxy.$Proxy**'的两种解决方法

这是我再做一个教务系统时遇到两次这样的问题,两次用下述不同的方法解决的,希望也能帮助到你.

这个错误的原因是spring aop代理混用的问题,如果想要了解什么是Spring aop代理与为什么会混乱,自己去百度吧,我还是直奔主题哈,相信大家解决问题心切.

第一种解决的方法:

在applicationContext.xml文件里面的

  1. <!--开启基于注解的事务,使用xml配置形式的事务(必要主要的都是使用配置式) -->

  2. <aop:config>

  3. <!-- 切入点表达式 -->

  4. <aop:pointcut expression="execution(* com.qihang.service..*(..))" id="txPoint"/>

  5. <!-- 配置事务增强 -->

  6. <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>

  7. </aop:config>

这个语句的下面添加这样一句话

<aop:aspectj-autoproxy  proxy-target-class="true"/>

添加后的效果:

  1. <!--开启基于注解的事务,使用xml配置形式的事务(必要主要的都是使用配置式) -->

  2. <aop:config>

  3. <!-- 切入点表达式 -->

  4. <aop:pointcut expression="execution(* com.qihang.service..*(..))" id="txPoint"/>

  5. <!-- 配置事务增强 -->

  6. <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>

  7. </aop:config>

  8. <aop:aspectj-autoproxy proxy-target-class="true"/>

然后运行一下项目试试吧,如果还不行就试试下面的方法,上面要求添加的语句也不要删了哦

第二种方法:

这是我在SSM+shiro继承开发的时候遇到的问题,出的错误类型也是 org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'xuejiService' is expected to be of type 'com.qihang.serviceImpl.XuejiServiceImpl' but was actually of type 'com.sun.proxy.$Proxy33'

在用shiro的时候有一段配置是这样的:

  1. <!--

  2. 5.启用了IOC容器中使用shiro的注解

  3. 注意:只有在配置了LifecycleBeanPostProcessor之后才可以

  4. -->

  5. <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"

  6. depends-on="lifecycleBeanPostProcessor">

  7. </bean> <!--此处的depends-on与上面的LifecycleBeanPostProcessor配置的id保持一致-->

  8. <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">

  9. <property name="securityManager" ref="securityManager"/>

  10. </bean>

这也是

DefaultAdvisorAutoProxyCreator

所使用代理器混乱的问题:需要在里面添加下面的一句话:

<property name="proxyTargetClass" value="true"/>

添加后的效果为:

  1. <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"

  2. depends-on="lifecycleBeanPostProcessor">

  3. <property name="proxyTargetClass" value="true"/>

  4. </bean> <!--此处的depends-on与上面的LifecycleBeanPostProcessor配置的id保持一致-->

  5. <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">

  6. <property name="securityManager" ref="securityManager"/>

  7. </bean>

这两个方法所需要添加的语句都添加上后,项目应该就能运行了,如果还是报同样错误的话 ,就找找你现在用的框架,所写的配置文件里面是不是也有类似代理的语句,然后百度一下该代理对应的参数,类似于上述情况配置一下,应该就ok了!

but was actually of type 'com.sun.proxy.$Proxy**'的两种解决方法相关推荐

  1. No qualifying bean of type xxx‘ available 的一种解决方法

    No qualifying bean of type xxx' available 的一种解决方法 参考文章: (1)No qualifying bean of type xxx' available ...

  2. SSH登录时“no matching host key type found. Their offer: ssh-rsa,ssh-dss“的错误解决方法

    问题描述 在利用SSH登录某目标时,出现下述报错: ssh loneferret@192.168.140.146 Unable to negotiate with 192.168.140.146 po ...

  3. python报错TypeError: unsupported operand type(s) for -: ‘decimal.Decimal‘ and ‘float‘的解决方法

    问题描述 在编写python代码时,进行小数位相减时出现 TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'fl ...

  4. “Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“解决方法

    项目接口返回 code: 500 data: null message: "Content type 'application/x-www-form-urlencoded;charset=U ...

  5. 【问题解决】mybatis 类型不匹配两种解决办法 -Result type not match for select id=“selectUser“ srcType: com.kuang.pojo

    问题描述: Result type not match for select id="selectUser"srcType: com.kuang.pojo.UsertargetTy ...

  6. Property ‘next‘ does not exist on type ‘Component<any, {}, any>‘问题的解决方法

    场景:使用antd的Carousel组件时,自定义左右切换按钮,触发组件的next(),prev()方法时报错 错误写法: handleNext(){this.refs.img.next()}< ...

  7. import sun.misc.BASE64Decoder;import sun.misc.BASE64Encoder; 报错的解决方法

    这是因为这个类不属于JDK标准库范畴,但在JDK中包含了该类,可以直接使用.但是在eclipse中直接使用却报错. 转载于:https://www.cnblogs.com/yangxiaomei/p/ ...

  8. Could not find artifact com.sun:tools:jar:1.5.0 解决办法

    2019独角兽企业重金招聘Python工程师标准>>> Could not find artifact com.sun:tools:jar:1.5.0 解决办法 创建maven项目出 ...

  9. jmeter报“msg“:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“的解决方法

    jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supp ...

最新文章

  1. LSM树——放弃读能力换取写能力,将多次修改放在内存中形成有序树再统一写入磁盘...
  2. LeetCode Excel Sheet Column Number(进制转换问题)
  3. MongoDB 小试牛刀
  4. Java多线程(四)之ConcurrentSkipListMap深入分析
  5. 疯狂软件mysql视频_疯狂软件MySql视频
  6. 7-323 逆波兰表达式 (10 分)
  7. 七种武器武装.NET(常用开发工具介绍)(转)
  8. 孩子要经历什么后,才能懂得学业的重要和父母的不易?
  9. delphi webservice 如何 共享 变量_医疗质量|如何实现非药物医嘱闭环管理?
  10. 他毕业1年,换了5份工作,为什么失业的总是他?
  11. Ubuntu vi命令
  12. 一文详解自然语言处理任务之共指消解
  13. 昆仑固件涉密专用计算机,存储处理国家秘密的计算机信息系统按照涉密程序实行...
  14. Tableau怎么制作专业图表
  15. scrapy框架携带cookie访问淘宝购物车功能的实现代码!
  16. SkyWalking 概念与设计总览
  17. python注释是什么意思_python中注释的意思是什么
  18. 剑指Offer题目详解(CPP、JAVA)
  19. 卡马克:用C++进行函数式编程
  20. php initlize,PHP 反序列化漏洞入门学习笔记

热门文章

  1. 使用SQL脚本创建数据库,操作主键、外键与各种约束(MS SQL Server)
  2. MySQL表名不区分大小写的设置方法
  3. java5年转c语言,时隔5年,C语言再次领先Java,荣登编程语言排行榜第一!
  4. html不居中代码,HTML – 为什么我不能居中div?
  5. linux 网络命令
  6. comsol稀物质传递_什么是质量传递?
  7. dnf无限重连服务器,dnf无限连接服务器失败解决方法
  8. php7 编译参数详解,php7.4.5编译安装参数变更
  9. java的imshow方法_如何在循环中使用子图,imshow或图形来显示所有图像?
  10. vi执行Linux命令,如何从Vim中访问shell或运行外部命令