Java @预匹配在Jersey中不使用动态绑定

Java @预匹配在Jersey中不使用动态绑定,java,rest,jersey,Java,Rest,Jersey,我试图在API调用到达资源方法之前对其进行清理。我决定最好的方法是创建过滤器并动态绑定它们。但是,@PreMatching注释只有在我将其设置为全局时才起作用。我的代码是下一个: 过滤器: @PreMatching public class FilterTest implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext crc) throws IOExcept

我试图在API调用到达资源方法之前对其进行清理。我决定最好的方法是创建过滤器并动态绑定它们。但是,
@PreMatching
注释只有在我将其设置为全局时才起作用。我的代码是下一个:

过滤器:

@PreMatching
public class FilterTest implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext crc) throws IOException {

        UriBuilder ub = crc.getUriInfo().getRequestUriBuilder();
        ub.replaceQueryParam("count", 20);
        crc.setRequestUri(ub.build());

    }

}
动态绑定类:

@Provider
public class DynamicTest implements DynamicFeature {

    @Override
    public void configure(ResourceInfo ri, FeatureContext fc) {
        if (MyResourceClass.class.equals(ri.getResourceClass())){
            fc.register(FilterTest.class);

        }
    }

}
泽西岛应用程序文件:

public class JerseyApplication extends ResourceConfig {

    public JerseyApplication() {
        ...
        register(DynamicTest.class);
    }

}
错误:

HTTP 500 - java.lang.IllegalStateException: Method could be called only in pre-matching request filter.
我能做什么