Java 如何在jersey WriterInterceptor实现中获取@interface参数

Java 如何在jersey WriterInterceptor实现中获取@interface参数,java,annotations,jersey,jax-rs,interceptor,Java,Annotations,Jersey,Jax Rs,Interceptor,例如,我有一个接口 @NameBinding @Retention(RetentionPolicy.RUNTIME) public @interface AutoLogged { boolean query() default false; } 如何在拦截器实现中获取query参数 @Provider @AutoLogged public class AutoLoggedInterceptor implements WriterInterceptor { @Context

例如,我有一个接口

@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoLogged {
    boolean query() default false;
}
如何在拦截器实现中获取
query
参数

@Provider
@AutoLogged
public class AutoLoggedInterceptor implements WriterInterceptor {
    @Context
    private ResourceInfo resourceInfo;

    @Override
    public void aroundWriteTo(final WriterInterceptorContext context)
            throws IOException, WebApplicationException {
        try {
            final String methodName = this.resourceInfo.getResourceMethod().getName();
            BasicAutoLoggedProducer.makeCall(methodName);
        } catch (final Exception e) {
            e.printStackTrace(System.err);
        } finally {
            context.proceed();
        }
    }
}
我在context.getPropertyNames中找不到它。我使用getAnnotations方法看到注释
自动标记
。如何从界面中检索参数
查询

您只需

AutoLogged annotation = resourceInfo.getResourceMethod().getAnnotation(AutoLogged.class);
if (annotation != null) {
    boolean query = annotation.query();
}
“并要设置参数
查询


我不太清楚你的意思,但是如果你的意思是想在运行时设置值,我也不确定目的和方法。希望你们能用“get”而不是“set”:-

我的意思是在用@autologd注释方法时查询
set
。并在实现中获取
。谢谢,准备好了吗?在注释某个内容时设置它。例如,在您的资源方法
@autologd(query=true)
中。所有这些都是声明性元数据。您获取元数据并根据它决定要做什么。正确地说,这是一个表述错误的问题。