切点类
public class DemoService {
public void demoMethod(String name, int age) {
System.out.println("DemoMethod execute,name:" + name + " age:" + age);
}
}
xml
<bean id="demo" class="com.lee.service.DemoService"/>
<bean id="myadvice" class="com.lee.advice.MyAdvice"/>
<aop:config>
<aop:pointcut expression="execution(* com.lee.service.DemoService.demoMethod(String,int)) and args(name1,age1)" id="mypoint"/>
<aop:aspect ref="myadvice">
<aop:before method="beforeMethod" pointcut-ref="mypoint" arg-names="name1,age1"/>
</aop:aspect>
</aop:config>
通知方法
public class MyAdvice {
public void beforeMethod(String name1, int age1) {
System.out.println("before name:" + name1 + " age:" + age1);
}
}
注意,通知方法中的参数名要与xml中<aop:pointcut>中args、<aop:before>中arg-names相对应