未使用 Quarkus 调用 aroundInvoke

yog*_*ger 6 quarkus

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

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

和这个资源:

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");
    }
}
Run Code Online (Sandbox Code Playgroud)

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

小智 1

根据Quarkus CDI 参考指南

  • 不支持@Interceptors

您需要将@Priority@Interceptor和绑定注释添加到您的拦截器类中。请参阅此处的示例