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