今天继续学习《Spring in action 3rd》并运行书中的例子,到了第4章aop,是加入一个作为切面的Audience类,将Performer的perform()方法作为切点来进行切入。

相关代码:

<aop:aspect ref="audience">
<aop:pointcut id="performance" expression="execution(* com.springinaction.springidol.Performer.perform(..))" />
<aop:before pointcut-ref="performance" method="takeSeats"/>
<aop:before pointcut-ref="performance" method="turnOffCellphone"/>
<aop:after-returning pointcut-ref="performance" method="applaud"/>
<aop:after-throwing pointcut-ref="performance" method="demandRefund"/>
</aop:aspect>
package com.springinaction.springidol;

public class Audience {
public void takeSeats(){
System.out.println("The audience is taking their seats.");
}
public void turnOffCellphone(){
System.out.println("The audience is turning off their cellphones.");
}
public void applaud(){
System.out.println("CLAP CLAP CLAP CLAP.");
}
public void demandRefund(){
System.out.println("Boo! We want out money back!");
}
}

这样在测试的时候报以下2个错误:

java.lang.NoClassDefFoundError:org/aopalliance/aop/Advice
java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException

我们需要在之前导入的spring-framework-3.2.11.RELEASE-dist.zip基础上,再导入com.springsource.org.aopalliance-1.0.0.jar、aspectj-1.6.13.jar两个包。它们都可以在各自的官方网站上下载。

特别的是,直接导入aspectj-1.6.13.jar是不行的,需要将其解压缩,然后将解压出来的aspectjrt.jar、aspectjtools.jar、aspectjweaver.jar、org.aspectj.matcher.jar导入eclipse项目中即可,如下图所示。

最新文章

  1. Asp.Net MVC&lt;四&gt;:路由器
  2. Bash:-:-获取未来40天的日期
  3. 腾讯优测优分享 | 游戏的UI自动化测试可以这样开展
  4. javascript 位运算
  5. javascript的语法结构
  6. No connection string named &#39;***&#39; could be found in the application config file
  7. QtSpim实现MIPS指令的编写
  8. aspose调用打印机打印文档
  9. 多条件判断语句case
  10. [Ruby学习总结]Ruby中的类
  11. 关于lvs+keepalived只加入一台realserver问题
  12. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(20)-多条件模糊查询和回收站还原的实现
  13. window与linux互相拷贝文件
  14. Bootstrap入门(十六)组件10:well和具有响应式特性的嵌入内容
  15. JAVA 中数组的几种排序方法
  16. unity 竖屏不能全屏显示
  17. bash: pip: command not found... 解决方法
  18. [BOI2004]Sequence 数字序列(左偏树)
  19. three.js初探,立体几何入手(一)
  20. Python每日练习汇总

热门文章

  1. Git Submodule 使用简介
  2. oracle基本查询入门(一)
  3. 《Google软件测试之道》摘录
  4. Spring框架的事务管理的分类
  5. bootstrap下modal模态框中webuploader控件按钮异常(无法点击)问题解决办法【转】
  6. C语言文本处理
  7. final修饰符:
  8. Yandex插件使用说明——Slager_Z
  9. mybatis 传参为 Integer 时 ,Mapper 文件 中判断 条件 问题。
  10. mybatis 和 mybatis-spring