38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package com.anno;
|
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.*;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@Component("myAspect")
|
|
@Aspect //标注切面
|
|
public class myAspect {
|
|
@Before("execution(* *.*.*.show(..))")
|
|
public void show1(){
|
|
System.out.println("前置增强。。。。");
|
|
}
|
|
|
|
@AfterReturning("pointcut()")
|
|
public void show2(){
|
|
System.out.println("后置增强。。。。");
|
|
}
|
|
@Around("pointcut()")
|
|
public Object show3(ProceedingJoinPoint pjp) throws Throwable {
|
|
System.out.println("环绕前增强。。。。");
|
|
Object proceed = pjp.proceed();//切点方法
|
|
System.out.println("环绕后增强。。。。");
|
|
return proceed;
|
|
}
|
|
@AfterThrowing("pointcut()")
|
|
public void show4(){
|
|
System.out.println("异常抛出增强。。。。");
|
|
}
|
|
@After("pointcut()")
|
|
public void show5(){
|
|
System.out.println("最终增强。。。。");
|
|
}
|
|
//指定切点
|
|
@Pointcut("execution(* *.*.*.show(..))")
|
|
public void pointcut(){}
|
|
}
|