package com.yr.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class MyAspect {
@Pointcut(“execution(* com.yr.server.impl..(…))”)
public void doPointCut(){}
@Before("doPointCut()")
public void bofore(){
System.out.println("前置通知");
}
@After("doPointCut()")
public void after(){
System.out.println("最终通知");
}
@AfterReturning(value="doPointCut()",returning="returnVal")
public void afterReturn(Object returnVal){
//System.out.println(returnVal);
System.out.println("后置通知");
}
@Around("doPointCut()")
public Object round(ProceedingJoinPoint jp) throws Throwable{
System.out.println("环绕通知前");
Object obj= jp.proceed();
System.out.println("环绕通知之后");
return obj;
}
@AfterThrowing(value="doPointCut()",throwing="e")
public void expection(JoinPoint jp,Throwable e){
System.out.println(jp.getSignature().getName());
System.out.println("异常通知");
}
}
注意:在application.xml文件中配置<aop:aspectj-autoproxy/>
捕获的是server层的异常