spring aop 注解的使用

QQ20180904-142224

@Aspect
@Component
public class Log {

    @Pointcut("execution (* com.jiutong.xhmp.service.UserService.create())")
    public void access(){
        System.out.println();
    }
    @Before("access()")
    public void doBefore() {
        System.out.println("doBefore advice");
    }

    @AfterReturning("access()")
    public void doAfterReturning() {
        System.out.println("doAfterReturning advice");
    }

    @After("access()")
    public void doAfter() {
        System.out.println("doAfter advice");
    }

    @AfterThrowing("access()")
    public void doAfterThrowing() {
        System.out.println("doAfterThrowing advice");
    }

    @Around("access()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("doAround advice start");
        Object result = pjp.proceed();
        System.out.println("doAround advice end");
        return result;
    }
}

(全文完)

(转载本站文章请注明作者和出处 spring aop 注解的使用