- applicationContext.xml中添加<aop:aspectj-autoproxy></aop:aspectj-autoproxy>,然后
@Component
public class LogInterceptor{}相当于implements InvocationHandler
@Pointcut("execution(public * com.gxk.service..*.my(..))")
public void myMethod(){}
@Before("myMethod()")
public void before(){
System.out.println("before");
}
@AfterReturning("execution(* com.gxk.dao.impl.UserDAOImpl.*(..))")
public void after(){
System.out.println("after");
}
@AfterThrowing("execution(* com.gxk.dao.impl.UserDAOImpl.*(..))")
public void throw1(){
System.out.println("throw");
}
@Around("myMethod()")
public void around(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("around start");
pjp.proceed();
System.out.println("around end");
}