基于配置文件的方式配置AOP
<aop:config>
配置切点表达式
<aop:pointcut expression="execution(* 类名.*(int,int)) id="pointcut"/>
配置切面及通知
<aop:aspect ref="loggingAspect(上文已经配置过的切面的bean)" order="1(优先级)">
<aop:before method="beforeMethod(方法名)" pointcut-ref="pointcut(上文的切点)"
<aop:after-throwing/>异常抛出
<aop:after-returning/>返回通知
<aop:around/>环绕,全部输出
</aop:aspect>
</aop:config>
基于注解的方式配置AOP
切面
@Order(2)优先级
@Component
@Aspect
public class LoggingAspect{
@Before("execution(类名.*(..))")
public void beforeMethod(JoinPoint joinPoint){}
@AfterReturning(value="execution(public int com.yl.spring.aop.ArithmeticCalculator.*(..))", returning="result")
public void afterReturning(JoinPoint joinPoint, Object result) {}
@AfterThrowing(value="execution(public int com.yl.spring.aop.ArithmeticCalculator.*(..))", throwing="ex")
}