package cn.noexception.container.aop.framework.adapter; import cn.noexception.container.aop.MethodBeforeAdvice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; /** * MethodBeforeAdviceInterceptor * - 方法拦截器 * @author 吕滔 * @Date 2021/11/4 16:34 */ public class MethodBeforeAdviceInterceptor implements MethodInterceptor { private MethodBeforeAdvice advice; public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) { this.advice = advice; } /** * 实现了 MethodInterceptor 接口,调用 advice 中的 before 方法,传入对应的参数信息。 * @param invocation * @return * @throws Throwable */ @Override public Object invoke(MethodInvocation invocation) throws Throwable { this.advice.before(invocation.getMethod(), invocation.getArguments(), invocation.getThis()); return invocation.proceed(); } }