![]()
@Component
@Aspect/*生成代理对象*/
@Order(0)
public class LogProxy {
@Pointcut(value="execution(* com.levi..*.*(..))")
public void pointcut1(){}
@Before("pointcut1()")
public void before(){} //方法执行之前执行
@AfterReturning("pointcut1()")
public void afterReturning(){} //返回值之后执行,有异常不会执行
@AfterThrowing("pointcut1()")
public void afterThrowing(){} //方法异常之后执行
@After("pointcut1()")
public void after(){} //方法执行之后,总是执行的
@Around("pointcut1()")
public void around(ProceedingJoinPoint pjp){
System.out.println("方法执行之前执行");
try{
pjp.proceed(); //执行方法
System.out.println("方法执行之后执行");
}catch(Throwable e){
System.out.println("异常执行");
}finally{
System.out.println("总是执行的");
}
}
}
<!--开启aop-->
<aop:aspectj-autoproxy proxy-target-class="true"/>
![]()