ToB企服应用市场:ToB评测及商务社交产业平台

标题: quarkus依赖注入之十二:禁用类级别拦截器 [打印本页]

作者: 十念    时间: 2023-8-11 07:51
标题: quarkus依赖注入之十二:禁用类级别拦截器
欢迎访问我的GitHub

这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos
本篇概览


类拦截器和方法拦截器的叠加效果


  1. @InterceptorBinding
  2. @Target({ElementType.TYPE, ElementType.METHOD})
  3. @Retention(RetentionPolicy.RUNTIME)
  4. public @interface TrackClass {
  5. }
复制代码
  1. @TrackClass
  2. @Interceptor
  3. public class TrackClassInterceptor {
  4.     @AroundInvoke
  5.     Object execute(InvocationContext context) throws Exception {
  6.         Log.info("from TrackClass");
  7.         return context.proceed();
  8.     }
  9. }
复制代码
  1. @InterceptorBinding
  2. @Target({ElementType.TYPE, ElementType.METHOD})
  3. @Retention(RetentionPolicy.RUNTIME)
  4. public @interface TrackMethod {
  5. }
复制代码
  1. @TrackMethod
  2. @Interceptor
  3. public class TrackMethodInterceptor {
  4.     @AroundInvoke
  5.     Object execute(InvocationContext context) throws Exception {
  6.         Log.info("from TrackMethod");
  7.         return context.proceed();
  8.     }
  9. }
复制代码
  1. @ApplicationScoped
  2. @TrackClass
  3. public class ExcludeInterceptorDemo {
  4.     public void test0() {
  5.         Log.info("from test0");
  6.     }
  7.     @TrackMethod
  8.     public void test1() {
  9.         Log.info("from test1");
  10.     }
  11. }
复制代码
  1. @QuarkusTest
  2. public class ExcludeInterceptorTest {
  3.    
  4.     @Inject
  5.     ExcludeInterceptorDemo excludeInterceptorDemo;
  6.     @Test
  7.     public void test() {
  8.         excludeInterceptorDemo.test0();
  9.         Log.info("*****************************");
  10.         excludeInterceptorDemo.test1();
  11.     }
  12. }
复制代码

用注解NoClassInterceptors使类拦截器失效


NoClassInterceptors的影响范围


源码下载

名称链接备注项目主页https://github.com/zq2599/blog_demos该项目在GitHub上的主页git仓库地址(https)https://github.com/zq2599/blog_demos.git该项目源码的仓库地址,https协议git仓库地址(ssh)git@github.com:zq2599/blog_demos.git该项目源码的仓库地址,ssh协议
欢迎关注博客园:程序员欣宸

学习路上,你不孤单,欣宸原创一路相伴...

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4