1创建拦截器注解 import javax.interceptor.InterceptorBinding; import java.lang.annotation.*; @Inherited @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD,ElementType.TYPE}) public @interface LogEvent { }
2创建拦截器
import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; @LogEvent @Interceptor public class LogEventInterceptor { @AroundInvoke public Object logEvent(InvocationContext ctx) throws Exception { System.out.println("method:"+ctx.getMethod().getName()+"param:"+ctx.getParameters()); return ctx.proceed(); } }
3在需要拦截的方法或类上加上@LogEvent 注解接口
全部评论