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) { }
标签:sl,Spring,AOP,切点,annotation,SystemLog,logAspect,public 来源: https://www.cnblogs.com/KL2016/p/16067887.html