import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
@Aspect
@Component
public class ICacheAopAction {
@Pointcut("@annotation(com.cdms.aop.ICache)")
private void controllerAspect(){}
@Before("controllerAspect()")
public void Before(JoinPoint joinPoint){
String classname = joinPoint.getTarget().getClass().getSimpleName();
String methodName = joinPoint.getSignature().getName();
List<Object> args = Arrays.asList(joinPoint.getArgs());
System.out.println("@before Execute! --class name: " + classname + ", method name: " + methodName + " " + args );
}
@Around("controllerAspect()")
public Object Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("@Around:执行目标方法之前...");
Object obj= proceedingJoinPoint.proceed();
System.out.println("@Around:执行目标方法之后...");
System.out.println("@Around:被织入的目标对象为:" + proceedingJoinPoint.getTarget());
System.out.println( "@Around:原返回值:" + obj + ",这是返回结果的后缀");
return obj;
}
@AfterThrowing("controllerAspect()")
public void AfterThrowing(){
System.out.println("异常通知....");
}
@After("controllerAspect()")
public void After(JoinPoint point){
System.out.println("@After:模拟释放资源...");
System.out.println("@After:目标方法为:" +
point.getSignature().getDeclaringTypeName() +
"." + point.getSignature().getName());
System.out.println("@After:参数为:" + Arrays.toString(point.getArgs()));
System.out.println("@After:被织入的目标对象为:" + point.getTarget());
}
@AfterReturning("controllerAspect()")
public void AfterReturning(JoinPoint point){
System.out.println("@AfterReturning:模拟日志记录功能...");
System.out.println("@AfterReturning:目标方法为:" +
point.getSignature().getDeclaringTypeName() +
"." + point.getSignature().getName());
System.out.println("@AfterReturning:参数为:" +
Arrays.toString(point.getArgs()));
System.out.println("@AfterReturning:返回值为:" );
System.out.println("@AfterReturning:被织入的目标对象为:" + point.getTarget());
}
}```
切面
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...