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开发常见错误的更多相关文章

  1. Java避坑宝典《Java业务开发常见错误100例》上线了

    写这个专栏的缘起 之前我写过一篇博客:<朱晔的互联网架构实践心得S2E2:写业务代码最容易掉的10种坑>,引起的关注还是挺多的.后来和极客时间的编辑一拍即合决定以这个为题写一个专栏.其实所 ...

  2. Spring AOP开发时如何得到某个方法内调用的方法的代理对象?

    Spring AOP开发时如何得到某个方法内调用的方法的代理对象? 问题阅读起来拗口,看代码 在方法中调用其他方法很常见,也经常使用,如果在一个方法内部调用其他方法,比如 public class U ...

  3. WCF分布式开发常见错误解决(1):An error occurred while attempting to find services at...添加服务引用出错

          WCF分布式开发常见错误解决(1):An error occurred while attempting to find services at...添加服务引用出错   当我们在客户端添 ...

  4. Spring AOP开发

    --------------------siwuxie095                                 Spring AOP 开发         1.在 Spring 中进行 ...

  5. Spring应用开发常见规范

    1.Spring应用开发常见包命名规范 controller:控制器 service:服务-接口 impl:服务-实现 integration sao:调用其他模块的,把feign的调用放到这个下面 ...

  6. 开发常见错误解决(6)WSE3.0未处理的WebException,未处理的Web异常,基础连接以及关闭...

    开发常见错误解决(6)WSE3.0未处理的WebException,未处理的Web异常,基础连接以及关闭. 我们在调试WSE服务端服务的时候会抛出,未处理的Web异常,基础连接以及关闭的异常信息.如图 ...

  7. 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 ...

  8. iOS开发 常见错误

    一.NSAppTransportSecurity 错误提示:NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL ...

  9. Android开发常见错误及技巧

    1.无法使用网络:Permission denied(maybe missing internet permission) 在AndroidMainifest.xml中增加允许使用网络选项(在< ...

随机推荐

  1. Doctype文档类型、作用及触发方式

    Doctype文档类型 1)  该标签可声明三种 DTD 类型,分别表示严格版本.过渡版本以及基于框架的 HTML 文档. 2)  HTML 4.01 规定了三种文档类型:Strict.Transit ...

  2. 数据库系统概论(第5版) P262 例8.12

    #include <iostream> #include <stdlib.h> #include <stdio.h> #include <Windows.h& ...

  3. 自定义listview的步骤

    1.定义一个实体类: public class Fruit { private String name; private int imageId; public Fruit(String name, ...

  4. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  5. codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)

    题目链接: C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 ...

  6. UVA-10269 (floyd+dijkstra)

    题意: 现在有A个村庄,B个城堡,现在要从1到A+B,有M条路,魔法鞋最多能用K次,每次的长度不超过L,且起点和终点一定是村庄和城堡,而且每次使用魔法鞋不能穿过城堡,问最短时间是多少; 思路: 先用F ...

  7. UESTC 914 方老师的分身I Dijkstra

    题意:求有向图的往返最短路的最长长度. 分析:求第一次到所有点的距离可以用一次Dijkstra求最短路求出来.考虑回来的路,想想就知道,从每个点回来的路即为将边的方向反转再求一次最短路后的结果. 所以 ...

  8. Doxygen Tool For Unity

    一.准备阶段 在之前的一系列文章中,我尝试了不同方法为Unity的C#生成脚本手册(帮助文档) 使用Doxygen生成C#帮助文档 为Unity项目生成文档(一)为Unity项目生成文档(二) 建议的 ...

  9. Jenkins学习六:修改Jenkins用户的密码

    很多时候在使用jenkins的时候忘记密码了,遇到这种情况,可以看看下面的讲解. Jenkins专有用户的数据存放在JENKINS_HOME/users目录.users目录的结构你一看就懂.users ...

  10. iOS数据本地持久化

      p1:归档.Preference(NSUserDefault).沙盒存储 iOS开发中本地存储主要有三种形式 XML属性列表(plist)归档 Preference(偏好设置) NSKeyedAr ...