package com.cy.pj.common.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 SysTimeAspect {
/**
* 切入点
*/
@Pointcut("bean(sysMenuServiceImpl)")
public void doTime(){}
@Before("doTime()")
public void doBefore(JoinPoint jp){
System.out.println("time doBefore()");
}
@After("doTime()")
public void doAfter(){//类似于finally{}代码块
System.out.println("time doAfter()");
}
/**核心业务正常结束时执行
* 说明:假如有after,先执行after,再执行returning*/
@AfterReturning("doTime()")
public void doAfterReturning(){
System.out.println("time doAfterReturning");
}
/**核心业务出现异常时执行
* 说明:假如有after,先执行after,再执行Throwing*/
@AfterThrowing("doTime()")
public void doAfterThrowing(){
System.out.println("time doAfterThrowing");
}
@Around("doTime()")
public Object doAround(ProceedingJoinPoint jp)
throws Throwable{
System.out.println("doAround.before");
try {
Object obj=jp.proceed();
return obj;
}catch(Throwable e) {
System.out.println("doAround.error-->" e.getMessage());
throw e;
}finally {
System.out.println("doAround.after");
}
}
}
END 十期推荐 【231期】面试官:Java中 serialVersionUID 的作用是什么? 【232期】面试官:Spring的 IOC 容器比New对象究竟好在哪? 【233期】面试官:什么是耦合?解耦合的方法有哪几种? 【234期】30个 Java 集合面试必备的问题和答案 【235期】面试官:Redis的数据是存在内存里吗?谈谈Redis各种数据类型的使用场景? 【236期】面试官:线程池中多余的线程是如何回收的? 【237期】面试官:如何发现 Redis 热点 Key ,解决方案有哪些? 【238期】面试官:Redis新版本开始引入多线程,谈谈你的看法? 【239期】面试官:如何使用Redis实现电商系统的库存扣减? 【240期】面试官:你了解JVM的内存溢出吗? ? ~