在使用Spring AOP时,遇到如下的错误:

Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.spring.test.setter.Instrumentalist
at com.spring.test.setter.test.main(test.java:12)

  看报错信息,显示的是动态代理生成的类无法转换到我们自定义的实现类。

  解决办法:

  在aop:config标签中添加 proxy-target-class="true" 即可。

  【解释说明】

  按照博客的说法:http://blog.csdn.net/z69183787/article/details/17161297

  由于生成代理类有两种方式:JDK和CGLIB,一种是基于接口的,一种是基于类的。

  如果添加上面的属性则使用基于类的cglib的方式,相反,如果没有写或者是false则通过jdk的基于接口的方式生成代理类。

  

  当然,如果本身不是基于接口的,那么会自动使用cglib的方式,在这里很奇怪为什么没有自动走cglib的方式。

  个中缘由,还得去看aop的源码,这里先做下记录。

  下面是我自己的spring配置文件,仅供参考

    <aop:config proxy-target-class="true">
<aop:aspect ref="audience">
<aop:before pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="takeSeats"/>
<aop:before pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="turnOffCellPhones"/>
<aop:after-returning pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="applaud"/>
<aop:after-throwing pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="demandRefund"/>
</aop:aspect>
</aop:config>

Spring aop报错:com.sun.proxy.$Proxyxxx cannot be cast to yyy的更多相关文章

  1. Spring AOP报错

    八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRe ...

  2. Spring AOP 报错org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXXXX' defined in class path resource..........

    完整报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'befo ...

  3. Spring aop报错:com.sun.proxy.$Proxy cannot be cast to xxx

    准备使用AOP记录所有NamedParameterJdbcTemplate操作数据时的所有日志,没想到出现这个错误,折腾了好久,终于找出原因 解决方案:在 aop-config配置添加上: proxy ...

  4. Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误

    [转] 解决方法: http://forum.springsource.org/showthread.php?85016-IllegalArgumentException-with-Applicati ...

  5. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  6. Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property

    Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...

  7. Spring Boot报错 MultipartException The temporary upload...

    Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...

  8. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  9. 报错com.github.pagehelper.PageHelper cannot be cast to com.github.pagehelper.Dialect

    报错com.github.pagehelper.PageHelper cannot be cast to com.github.pagehelper.Dialect spring以及mybatis版本 ...

随机推荐

  1. CentOS6.5下载地址

    http://linux.xitongxz.net:808/201603/CentOS-6.5-x86_64-bin-DVD1.iso

  2. java字符格式

    http://blog.chinaunix.net/uid-12348673-id-3335300.html http://blog.csdn.net/zhouyong80/article/detai ...

  3. AJAXA进行分页(2)

    查询功能是开发中最重要的一个功能,大量数据的显示,我们用的最多的就是分页. 在ASP.NET 中有很多数据展现的控件,比如用的最多的GridView,它同时也自带了分页的功能.但是我们知道用GridV ...

  4. React 服务端渲染最佳解决方案

    最近在开发一个服务端渲染工具,通过一篇小文大致介绍下服务端渲染,和服务端渲染的方式方法.在此文后面有两中服务端渲染方式的构思,根据你对服务端渲染的利弊权衡,你会选择哪一种服务端渲染方式呢? 什么是服务 ...

  5. 1048: [HAOI2007]分割矩阵

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1184  Solved: 863[Submit][Status][Discuss] Descripti ...

  6. 微信小游戏 demo 飞机大战 代码分析 (三)(spirit.js, animation.js)

    微信小游戏 demo 飞机大战 代码分析(三)(spirit.js, animation.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码 ...

  7. Ubuntu18 中文乱码 问题 解决

    之前租的服务器没有中文乱码的问题,最近重装了一下系统, 出现了中文乱码, 以下是解决方案: 输入locale查看当前的语言是否是中文 root@ubuntu:~# locale LANG=zh_CN. ...

  8. Nuxt.js 基础入门教程

    原文链接 Vue 开发一个单页面应用,相信很多前端工程师都已经学会了,但是单页面应用有一个致命的缺点,就是 SEO 极不友好.除非,vue 能在服务端渲染(ssr)并直接返回已经渲染好的页面,而并非只 ...

  9. hprose 1.0(rpc 框架) - 内部数据标准

    hprose 1.0 内部数据标准 方法的描述  {    // 请求调用格式    'C'.writeString('method1').'a'.count($params).'{'.'m'.cou ...

  10. 数据结构-二叉树(Binary Tree)

    #include <stdio.h> #include <string.h> #include <stdlib.h> #define LIST_INIT_SIZE ...