but was actually of type 'com.sun.proxy.$Proxy**'的两种解决方法 2022-05-28 18:15 39阅读 0赞 错误描述:`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文件里面的 <!--开启基于注解的事务,使用xml配置形式的事务(必要主要的都是使用配置式) --> <aop:config> <!-- 切入点表达式 --> <aop:pointcut expression="execution(* com.qihang.service..*(..))" id="txPoint"/> <!-- 配置事务增强 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/> </aop:config> 这个语句的下面添加这样一句话 <aop:aspectj-autoproxy proxy-target-class="true"/> 添加后的效果: <!--开启基于注解的事务,使用xml配置形式的事务(必要主要的都是使用配置式) --> <aop:config> <!-- 切入点表达式 --> <aop:pointcut expression="execution(* com.qihang.service..*(..))" id="txPoint"/> <!-- 配置事务增强 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/> </aop:config> <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的时候有一段配置是这样的: <!-- 5.启用了IOC容器中使用shiro的注解 注意:只有在配置了LifecycleBeanPostProcessor之后才可以 --> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"> </bean> <!--此处的depends-on与上面的LifecycleBeanPostProcessor配置的id保持一致--> <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> <property name="securityManager" ref="securityManager"/> </bean> 这也是 DefaultAdvisorAutoProxyCreator 所使用代理器混乱的问题:需要在里面添加下面的一句话: <property name="proxyTargetClass" value="true"/> 添加后的效果为: <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"> <property name="proxyTargetClass" value="true"/> </bean> <!--此处的depends-on与上面的LifecycleBeanPostProcessor配置的id保持一致--> <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"> <property name="securityManager" ref="securityManager"/> </bean> 这两个方法所需要添加的语句都添加上后,项目应该就能运行了,如果还是报同样错误的话 ,就找找你现在用的框架,所写的配置文件里面是不是也有类似代理的语句,然后百度一下该代理对应的参数,类似于上述情况配置一下,应该就ok了! ## 转载来源:[but was actually of type ‘com.sun.proxy.$Proxy\*\*’的两种解决方法][but was actually of type _com.sun.proxy._Proxy] ## [but was actually of type _com.sun.proxy._Proxy]: https://blog.csdn.net/csdn___lyy/article/details/76687588 文章版权声明:注明蒲公英云原创文章,转载或复制请以超链接形式并注明出处。
相关 but was actually of type 'com.sun.proxy.$Proxy16' 报错信息如下 org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ゞ 浴缸里的玫瑰/ 2021年10月15日 21:33/ 0 赞/ 690 阅读
相关 fortran错误:the type of the actual argument differs from the type of the dummy argument 参考原文:https://blog.csdn.net/SinjoyWong/article/details/70138960 在用intel fortran写一个DLL程序 港控/mmm°/ 2021年12月06日 00:56/ 0 赞/ 60 阅读
相关 【解决方案】Expected object of type torch.FloatTensor but found type torch.DoubleTensor 简述 在网上找了半天没有得到解答。 但是,在pycharm输入`.`之后,发现有一个函数很有意思,然后得到了解决 解决方案 假如报错的语句是 `mod Dear 丶/ 2022年04月17日 14:29/ 0 赞/ 72 阅读
相关 The content of element type must match解决方法 当我在mybatis的核心配置文件SqlMapConfig.xml中配置别名的时候,老是提示错误。 ![70][] 把鼠标移到上去就可以看到详细的内容 如下图所示: ! 青旅半醒/ 2022年05月09日 18:28/ 0 赞/ 31 阅读
相关 but was actually of type [com.sun.proxy.$Proxy13] ssm在注解整合时提示Bean named 'studentservice' is expected to be of type 'com.shuai.service.imp. 逃离我推掉我的手/ 2022年05月12日 23:14/ 0 赞/ 96 阅读
相关 but was actually of type 'com.sun.proxy.$Proxy**'的两种解决方法 错误描述:`Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean 我不是女神ヾ/ 2022年05月28日 18:15/ 0 赞/ 40 阅读
相关 is expected to be of type but was actually of type 'com.sun.proxy.$Proxy70' spring boot项目,启动报这个异常 原因是:我通过@EnableTransactionManagement 启动了事务,但是没有开启cglib的动态代理。 appl 布满荆棘的人生/ 2022年06月04日 10:12/ 0 赞/ 43 阅读
相关 Bean named 'xxx' must be of type xxx , but was actually of type [com.sun.proxy.$Proxy189] nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: 我不是女神ヾ/ 2022年06月17日 18:53/ 0 赞/ 16 阅读
相关 使用spring遇到"BeanNotOfRequiredTypeException......but was actually of type [com.sun.proxy.$Proxy18]"异常 问题描述: > 在使用aspectJ申明事务管理时出现的异常 > > org.springframework.beans.factory.BeanNotOfR ╰半夏微凉°/ 2022年07月13日 23:55/ 0 赞/ 53 阅读
相关 invalid new-expression of abstract class type解决方法 记录一个小bug ![在这里插入图片描述][20210108145108564.png] 我在网上找了一下答案如下: > 出现这个错误原因是new 了一个抽象类出错, 傷城~/ 2023年01月03日 22:07/ 0 赞/ 8 阅读
还没有评论,来说两句吧...