spring aop开发常见错误
1.
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring-aop.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
解决方法:
下载引入 aopalliance-1.0.jar
使用spring aop 一般需要的依赖jar有: aopalliance-1.0.jar(AOP联盟的API包,里面包含了针对面向切面的接口。 通常Spring等其它具备动态织入功能的框架依赖此包。) 、aspectjweaver-1.5.3.jar、javassist-3.9.0.GA.jar(Javassist的(JAVA编程助手)使Java字节码操纵简单。这是一个编辑Java字节码的类库)。
2.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Instrumentalist' defined in class path resource [spring-aop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'illegal identifier start (。)' at character position 52
execution(* com.luchao.springaop.Performer.perform(。。))
解决方法:在工具下。。显示特别小,所有拿出来发现原来是。。的问题,把。。换成..就OK了。
3.
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.luchao.springaop.Instrumentalist
at com.luchao.springaop.AspectTest.audienceShouldApplaud(AspectTest.java:13)
at com.luchao.springaop.AspectTest.main(AspectTest.java:19)
Spring的文档中这么写的:Spring AOP部分使用JDK动态代理或者CGLIB来为目标对象创建代理。如果被代理的目标实现了至少一个接口,则会使用JDK动态代理。所有该目标类型实现的接口都将被代理。若该目标对象没有实现任何接口,则创建一个CGLIB代理。
所以,解决办法是,如果用JDK动态代理,就必须为被代理的目标实现一个接口(要注意的地方是:需要将ctx.getBean()方法的返回值用接口类型接收);如果使用CGLIB强制代理,就必选事先将CGLIB包导入项目,设置beanNameAutoProxyCreator的proxyTargetClass属性为true。
例如:
<aop:aspectj-autoproxy proxy-target-class="true"/>
解决方案:
public void audienceShouldApplaud() throws PerformanceException{
Performer performer = (Performer) applicationContext.getBean("Instrumentalist");
performer.perform();
}
spring aop开发常见错误的更多相关文章
- Java避坑宝典《Java业务开发常见错误100例》上线了
写这个专栏的缘起 之前我写过一篇博客:<朱晔的互联网架构实践心得S2E2:写业务代码最容易掉的10种坑>,引起的关注还是挺多的.后来和极客时间的编辑一拍即合决定以这个为题写一个专栏.其实所 ...
- Spring AOP开发时如何得到某个方法内调用的方法的代理对象?
Spring AOP开发时如何得到某个方法内调用的方法的代理对象? 问题阅读起来拗口,看代码 在方法中调用其他方法很常见,也经常使用,如果在一个方法内部调用其他方法,比如 public class U ...
- WCF分布式开发常见错误解决(1):An error occurred while attempting to find services at...添加服务引用出错
WCF分布式开发常见错误解决(1):An error occurred while attempting to find services at...添加服务引用出错 当我们在客户端添 ...
- Spring AOP开发
--------------------siwuxie095 Spring AOP 开发 1.在 Spring 中进行 ...
- Spring应用开发常见规范
1.Spring应用开发常见包命名规范 controller:控制器 service:服务-接口 impl:服务-实现 integration sao:调用其他模块的,把feign的调用放到这个下面 ...
- 开发常见错误解决(6)WSE3.0未处理的WebException,未处理的Web异常,基础连接以及关闭...
开发常见错误解决(6)WSE3.0未处理的WebException,未处理的Web异常,基础连接以及关闭. 我们在调试WSE服务端服务的时候会抛出,未处理的Web异常,基础连接以及关闭的异常信息.如图 ...
- Spring AOP 开发中遇到问题:Caused by: java.lang.IllegalArgumentException: warning no match for this type name: com.xxx.collector.service.impl.XxxServiceImpl [Xlint:invalidAbsoluteTypeName]
在网上找了很多,都不是我想要的,后来发现是我在springaop注解的时候 写错了类名导致的这个问题 @Pointcut("execution(* com.xxx.collector.ser ...
- iOS开发 常见错误
一.NSAppTransportSecurity 错误提示:NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL ...
- Android开发常见错误及技巧
1.无法使用网络:Permission denied(maybe missing internet permission) 在AndroidMainifest.xml中增加允许使用网络选项(在< ...
随机推荐
- Zabbix监控windows部署安装
Zabbix agent 在windows上安装部署 1. 下载与解压 地址: http://www.zabbix.com/downloads/2.4.0/zabbix_agents_2.4.0.w ...
- 如何用ZBrush确定头部五官的位置
之前和大家讲过如何在ZBrush中确定头部雕刻,在第一阶段中面数很少,只能将大型体雕刻出来,由于面数太少不能进行下面的雕刻.接下来第二阶段的调整,需要重新分布模型表面的网格,增加面数,进行五官的位置的 ...
- J2EE笔记2
1. 部署并启动 tomcat 服务器.1). 解压 apache-tomcat-6.0.16.zip 到一个非中文目录下2). 配置一个环境变量. java_home(指向 JDK 安装的根目录) ...
- html5 实现video标签的自定义播放进度条
现在随着html5的渐热,越来越多的web开发者都开始选择使用html5写出一些比较好的web应用. html代码: <!DOCTYPE html> <html lang=" ...
- HDU 4445 Crazy Tank --枚举
题意: n个物体从高H处以相同角度抛下,有各自的初速度,下面[L1,R1]是敌方坦克的范围,[L2,R2]是友方坦克,问从某个角度抛出,在没有一个炮弹碰到友方坦克的情况下,最多的碰到敌方坦克的炮弹数. ...
- BZOJ 1500 维修数列【Splay】
注意:1,内存限制,所以需要回收删除的点 2,当前节点的左连续区间和最大值=max(左子树的左连续区间和最大值,左子树的总和+当节点的值+max(右子树的左连续区间和最大值,0)):右连续区间和最大值 ...
- 定制你的Unity编辑器
Unity的编辑器可以通过写脚本进行界面定制,包括添加功能菜单,今天写游戏Demo用到了记录一下. 为Unity添加子菜单 示例程序 [AddComponentMenu("Defend Ho ...
- GetComponent
GetComponent 的几种写法: 1.AutoRotation cmp1=(AutoRotation) GetComponent(typeof(AutoRotation)); 2.AutoRot ...
- cotangent Laplacian
几何网格处理经常用到 cotangent laplacian矩阵.前几天把这个功能整合到我的Maya 转 Matlab插件了. 这里发一个利用cotangent laplacian计算特征向量并显示的 ...
- RDLC直接打印帮助类
代码 /// <summary> /// 打印帮助类 /// </summary> public class PrintHelper { private int m_curre ...