ContainerRequestFilter中的ResouceInfo为空

时间:2018-06-06 12:34:28

标签: java jersey dropwizard

尝试读取过滤器中的注释字段,该过滤器使用DynamicFeature动态绑定,我们使用注入的ResourceInfo类始终为null。代码中有以下内容。

@Provider
public class ValiditationFilter implements ContainerRequestFilter {

    @Context
    ResourceInfo resourceInfo;

    @Override
    public void filter(ContainerRequestContext containerRequestContext) {
        //filter login
        //Resource Info is null
        Method resourceMethod = this.resourceInfo.getResourceMethod(); 
    }


}

功能代码如下

public class ValidatetFeature implements DynamicFeature {

    private Injector injector;

    public ValidateFeature registerInjector(Injector injector) {
        this.injector = injector;
        return this;
    }

    @Override
    public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) {
        if(resourceInfo.getResourceMethod().getAnnotation(Validate.class) != null) {
            featureContext.register(injector.getInstance(ValiditationFilter.class));
        }
    }
}

this link我知道这是已知问题,但我该如何让它发挥作用。

提前致谢。

0 个答案:

没有答案