【问题标题】:AroundInvoke not called with Quarkus未使用 Quarkus 调用 AroundInvoke
【发布时间】:2025-12-24 04:15:06
【问题描述】:

我创建了以下调用类,当一个被拦截的方法被调用时应该被调用:

import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

@Interceptor
class TestAspect {

    @AroundInvoke
    public Object log(InvocationContext context) throws Exception {
        System.out.println("AroundInvoke method called");
        return context.proceed();
    }
}

还有这个资源:

import javax.interceptor.Interceptors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/test")
@Interceptors(TestAspect.class)
public class TestResource {

    @GET
    @Path("/")
    public String test() {
        System.out.println("Resource method called");
        return new String("test");
    }
}

但我只从资源中获取日志行。

【问题讨论】:

    标签: quarkus


    【解决方案1】:

    根据Quarkus CDI Reference Guide

    • 不支持@Interceptors

    您需要将@Priority@Interceptor 和绑定注释添加到您的Interceptor 类。见here for an example

    【讨论】:

      【解决方案2】:

      您需要通过在 beans.xml 中定义拦截器或在拦截器上添加 @Priority(number) 来激活拦截器。

      【讨论】: