Spring中AOP基于Annotation配置常用声明

来源:互联网 发布:微创打码软件下载 编辑:程序博客网 时间:2024/05/14 02:29
package com.bjsxt.aop;import org.aspectj.lang.ProceedingJoinPoint;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@Componentpublic class LogInterceptor {@Pointcut("execution(* com.bjsxt.service.*.add(..))")public void myMethod(){};@Before("myMethod()")public void before(){System.out.println("before start");}@AfterReturning("myMethod()")public void afterreturn(){System.out.println("after start");}@AfterThrowing("myMethod()")public void afterThrowing(){System.out.println("Throwing start");}@Around("myMethod()")public void around(ProceedingJoinPoint pjp) throws Throwable{System.out.println("around start");pjp.proceed();System.out.println("around end");}}

0 0