REST JAX-RS 自定义上下文提供程序不工作

REST JAX-RS Custom Context Provider not working

我在 Java 11 和 Tomcat 9 服务器上使用 glassfish Jersey JAX-RS。在@Context 对象在我的应用程序中变为空后,我最近将我的 Jersey 版本升级到 2.27。此对象属于第 3 方 API。

第 3 方 API 中的 Jersey 版本,具有上下文元素,是 1.19,而且它属于 com.sun 包,而不是我正在使用的 [=29] =]. 我调用的 Rest 方法如下所示:

@GET
@Produces(MediaType.APPLICATION_JSON)
public Pageable<Role> getRoles(@Context final Search search) throws ServerException {

    return new Pageable<>(identityManagementService.getRoles(), search);
}

调用以下内容:

public Pageable(final List<T> list, final Search search) {
    this.count = list.size();
    this.data = list;
    if (search.getLimiter() != null && search.getLimiter().getCount() != 0) {
        this.data = list.stream()
               .skip(search.getLimiter().getOffset())
                .limit(search.getLimiter().getCount())
                .collect(Collectors.toList());

} }

第 3 方 Pom.xml 有以下条目:

<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.19</version>
        <optional>true</optional>
        <exclusions>
            <exclusion>
                <artifactId>asm</artifactId>
                <groupId>asm</groupId>
            </exclusion>
        </exclusions>
    </dependency>

我的 pom.xml 中有以下条目:

<dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.27</version>
        </dependency> 

搜索对象在 运行 时变为空,导致我的应用程序失败。两个球衣版本之间是否存在任何兼容性问题,或者我是否遗漏了什么。有人已经在使用 Jersey JAX-RS 2.27 和 Java 11 了吗?

问题已解决。在将我的 Jersey 更新到 2.27 后,我指的是 HK2 包的 AbstractBinder。 Jersey Jax-RS 上的新版本与 HK2 脱钩。导入 org.glassfish.jersey.internal.inject.AbstractBinder 并实施相应的覆盖方法解决了这个问题。 此处发布的答案 帮助我解决了这个问题。

谢谢