在通知类中方法的参数要与配置中的参数个数与类型对应起来
// 通知类中的方法
public void mybefore1(String name){
System.out.println("前置:"+name);
}
// Spring配置
<bean id="myadvice" class="com.steer.advice.MyAdvice"></bean>
<aop:config>
<aop:aspect ref="myadvice">
<aop:pointcut expression="execution(* com.steer.test.Demo.demo1(String)) and args(name)" id="mypoint1"/>
<aop:before method="mybefore1" pointcut-ref="mypoint1" arg-names="name"/>
</aop:aspect>
</aop:config>
1 <aop:after/> 后置通知,是否出现异常都执行
2 <aop:after-returing/> 后置通知,只有当切点正确执行时执行
3 <aop:after/> 和<aop:after-returing/> 和
<aop:after-throwing/>执行顺序和配置顺序有关
4 execution() 括号不能扩上args
5 中间使用and 不能使用&& 由spring 把and 解析成&&
6 args(名称) 名称自定义的.顺序和demo1(参数,参数)对应
7 <aop:before/> arg-names=” 名称” 名称来源于
expression=”” 中args(),名称必须一样
7.1 args() 有几个参数,arg-names 里面必须有几个参数
7.2 arg-names=”” 里面名称必须和通知方法参数名对应
网友评论