Resteasy 3.5.0.Final App Engine 标准环境 - NoSuchFieldError SERVER_SENT_EVENTS_TYPE

Resteasy 3.5.0.Final on App Engine standard env - NoSuchFieldError SERVER_SENT_EVENTS_TYPE

我有一个非常基本的 Java8 应用程序,使用 Resteasy 3.1.4.Final 部署在 App Engine 标准环境中。

但是当我将 Resteasy 升级到 3.5.0.Final;

Uncaught exception from servlet java.lang.NoSuchFieldError: SERVER_SENT_EVENTS_TYPE at org.jboss.resteasy.core.ResourceMethodInvoker.isSseResourceMethod(ResourceMethodInvoker.java:162) at org.jboss.resteasy.core.ResourceMethodInvoker.(ResourceMethodInvoker.java:147) at org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:345) at org.jboss.resteasy.core.ResourceMethodRegistry.register(ResourceMethodRegistry.java:272) at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:223) at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:195) at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:181) at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:158) at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:77) at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:496) at org.jboss.resteasy.spi.ResteasyDeployment.startInternal(ResteasyDeployment.java:279) at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:86) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:119) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36) at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:643) at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:422) at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:892) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349) at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1406) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1368) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778) at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:522) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:244) at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:182) at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:97) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:680) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:642) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:612) at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run(JavaRuntime.java:806) at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:274) at java.lang.Thread.run(Thread.java:745)

所以这似乎与环境有关。 有解决的线索吗?

谢谢

我遇到了同样的问题。

我已经通过从我的 pom 文件中删除 org.jboss.resteasy.jaxrs-api.3.0.12.Final 解决了这个问题。

希望能解决您的问题。

我发布了我在 Github

中收到的@NicoNes 的回答

Hi @freddyboucher I don't think that this commit is responsible of the NoSuchFieldError you are dealing with. Resteasy 3.1.4.Final is an implementation of the JAX-RS-API 2.0.1 spec whereas 3.5.1.Final is an impl of the JAX-RS-API 2.1 spec. And the missing field you are talking about is coming from the javax.ws.rs.core.MediaType in JAX-RS-API 2.1. So can you please be sure that your runtime execution does not embed the wrong version o the JAX-RS-API ?

Let me know.

-Nicolas

他是对的,我在 pom.xml:

  <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>javax.ws.rs</groupId>
          <artifactId>javax.ws.rs-api</artifactId>
          <version>2.0.1</version>
        </dependency>
      </dependencies>
  </dependencyManagement>

升级到 2.1,解决了我的问题!

我遇到了同样的错误,通过排除 pom.xml

中的 jar 解决了这个问题
<dependencies>
          <dependency>
          [...]
            <exclusions>
                <exclusion>
                    <groupId>javax.ws.rs</groupId>
                    <artifactId>jsr311-api</artifactId>
                </exclusion>
            </exclusions>
  </dependency>
        </dependencies>

我遇到了同样的问题。 我想任何依赖都可能导致 javax.ws.rs-api.. 的错误版本。我不知道它到底是哪个依赖。但就在添加之后:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.1</version>
</dependency>

我的pom.xml问题解决了。不需要删除任何其他依赖项