com.zusmart.sample.interceptor.SelfInterceptor Maven / Gradle / Ivy
The newest version!
package com.zusmart.sample.interceptor;
import java.lang.reflect.Method;
import com.zusmart.inject.annotation.Component;
import com.zusmart.inject.annotation.Interceptor;
import com.zusmart.inject.interceptor.InterceptorFactory;
//此处测试拦截器去拦截含有Interceptor的类,且只拦截onBefore方法
@Component
@Interceptor(annotations = Interceptor.class)
public class SelfInterceptor extends InterceptorFactory {
@Override
protected void onBefore(Class> targetClass, Method targetMethod, Object[] arguments) throws Throwable {
System.out.println("拦截拦截器 - before -> " + targetClass.getName() + "#" + targetMethod.getName());
}
@Override
protected void onAfter(Class> targetClass, Method targetMethod, Object[] arguments, Object result) throws Throwable {
System.out.println("拦截拦截器 - after -> " + targetClass.getName() + "#" + targetMethod.getName());
}
@Override
protected boolean onIntercept(Class> targetClass, Method targetMethod, Object[] arguments) throws Throwable {
return "onBefore".equals(targetMethod.getName());
}
}