spring aop注解方式





    
    
    

@Component
@Aspect
public class Log {
//    切入点
    @Pointcut(value = "execution(public void org.spring.Hello.aop())")
    public void pt() {
    }

    public void before() {
        System.out.println("aop before");
    }

    public void after() {
        System.out.println("aop after");
    }

    public void exp() {
        System.out.println("aop ex");
    }

    public void fina() {
        System.out.println("aop fina");
    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        Object proceed = null;
        try {
            System.out.println("around前置通知");
            proceed = joinPoint.proceed(args);
            System.out.println("后置");
        } catch (Throwable throwable) {
            System.out.println("异常");

        } finally {
            System.out.println("最终");
        }
        return proceed;
    }

}

推荐环绕通知

你可能感兴趣的:(spring aop注解方式)