AOP实验讲解

来源:互联网 发布:魔音软件男变女 编辑:程序博客网 时间:2024/06/06 01:22
package cn.roderick.aop.advice;import java.util.Arrays;import org.aopalliance.intercept.MethodInterceptor;import org.aopalliance.intercept.MethodInvocation;public class AroundMethod implements MethodInterceptor {    public Object invoke(MethodInvocation methodInvocation) throws Throwable {        System.out.println("Method name : "                + methodInvocation.getMethod().getName());        System.out.println("Method arguments : "                + Arrays.toString(methodInvocation.getArguments()));        // 相当于  MethodBeforeAdvice        System.out.println("roderick AroundMethod : Before method roderick!");        try {            // 调用原方法,即调用CustomerService中的方法            Object result = methodInvocation.proceed();            // 相当于 AfterReturningAdvice            System.out.println("roderick AroundMethod : After method roderick!");            return result;        } catch (IllegalArgumentException e) {            // 相当于 ThrowsAdvice            System.out.println("roderick AroundMethod : Throw exception roderick!");            throw e;        }    }}
原创粉丝点击