JerseyTest和Spring以及创建ServletContext

JerseyTest和Spring以及创建ServletContext,spring,jersey,jersey-2.0,Spring,Jersey,Jersey 2.0,我正在从泽西1.16迁移到泽西2.7。我的应用程序正在运行和工作,但我在测试中遇到了问题 需要注意的事项: 该应用程序使用Spring,并由一个类ApplicationConfiguration.class进行配置。 应用程序没有web.xml-Jersey servlet和过滤器是通过编程方式配置的。 我正在使用jersey-spring3图书馆。 与使用jersey-spring3库相关,我必须在onStartup方法中添加一个变通方法 // The following line is re

我正在从泽西1.16迁移到泽西2.7。我的应用程序正在运行和工作,但我在测试中遇到了问题

需要注意的事项:
该应用程序使用Spring,并由一个类ApplicationConfiguration.class进行配置。 应用程序没有web.xml-Jersey servlet和过滤器是通过编程方式配置的。 我正在使用jersey-spring3图书馆。 与使用jersey-spring3库相关,我必须在onStartup方法中添加一个变通方法

// The following line is required to avoid having jersey-spring3 registering it's own Spring root     context.
// https://java.net/jira/browse/JERSEY-2038
servletContext.setInitParameter("contextConfigLocation", "");
问题是:
当测试启动时,SpringComponentProvider尝试初始化Spring,但有一个危险的假设,即我不知道如何更正基于xml的配置。看看代码,问题是这个块

    ServletContext sc = locator.getService(ServletContext.class);

    if(sc != null) {
        // servlet container
        ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
    } else {
        // non-servlet container
        ctx = createSpringContext();
    }
运行JUnit测试时,ServletContext为null,并调用createSpringContext

问题是:

有没有一种方法可以运行测试并指定ServletContext/ServletContainer?

我相信这一问题在本文中有所涉及

简而言之:他们从Jersey 2.x中删除了此功能,并将其视为功能请求(而不是回归),因此不将其视为高优先级项目