Spring AOP

 

(1)定义注解:    

@Target({ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SystemLog {
 
(2)定义切面:
@Aspect
@Component
public class SystemLogAspect implements Ordered {
 
 
(3)定义切点:(代表基于注解得切点方式)
(3.1) 基于注解方式
// 切点
@Pointcut("@annotation(light.mvc.aop.annotation.SystemLog)")
public void logAspect() {
}
(3.2) 动态代理全部拦截    (即对这个包下的所有类进行拦截)
@Pointcut("execution(*.org.idea.spring.aop.MyCalculate.*(..))")

 

 

 
 
(4)定义通知方式:    @AfterThrowing (异常抛出后)  @Around(value = "logAspect() && @annotation(sl)") 环绕通知
@AfterThrowing(pointcut = "logAspect() && @annotation(sl)", throwing = "e")
public void doAfterThrowing(JoinPoint joinPoint, SystemLog sl, Throwable e) {
}

 

 

 
 
 
posted @ 2022-03-28 16:50  KLAPT  阅读(23)  评论(0)    收藏  举报