Quarkus 未调用 AroundInvoke

AroundInvoke not called with Quarkus

我创建了以下调用 class,当调用拦截方法时应该调用它:

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");
    }
}

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

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

根据 Quarkus CDI Reference Guide

  • @Interceptors is not supported

您需要将 @Priority@Interceptor 和绑定注释添加到您的拦截器 class。参见 here for an example