NoSuchFieldError:INCLUDE_ALL

时间:2014-04-13 20:26:52

标签: java spring google-app-engine maven jersey-2.0

我在GAE上使用Jersey和Spring 我得到以下例外:

Uncaught exception from servlet
java.lang.NoSuchFieldError: INCLUDE_ALL
    at org.glassfish.jersey.server.ResourceConfig$State.<init>    (ResourceConfig.java:110)
    at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:351)
    at org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig.<init>(ResourceConfig.java:1014)
    at org.glassfish.jersey.server.ResourceConfig.forApplicationClass(ResourceConfig.java:325)
    at org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:442)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:294)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:219)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)

看看泽西岛代码我看到这是抛出的例外:

    public State() {
        super(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL);

着眼于&#39; ComponentBag&#39;我可以看到在运行时无法找到的公共字段。

public static final Predicate<ContractProvider> INCLUDE_ALL = Predicates.alwaysTrue();

在&#39;州内&#39;构造函数,字段&#39; INCLUDE_ALL&#39; &#39; ComponentBag&#39;无法在运行时找到。
它看起来像是一个类路径问题,但我找不到什么问题 我正在使用Maven - 这是我POM的相关部分。

   ... 
<properties>
    <appengine.app.version>5</appengine.app.version>
    <appengine.target.version>1.8.9</appengine.target.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jersey.version>2.7</jersey.version>
    <spring.version>3.2.3.RELEASE</spring.version>
</properties>
   ...
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
</dependency>

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>${jersey.version}</version>
</dependency>
    ...

4 个答案:

答案 0 :(得分:3)

如果有人偶然发现这个问题(或者它仍然是相关的),我发现在命令行中添加-verbose:class VM选项可以帮助您找出这个异常的确切位置。

ResourceConfig来自jersey-server-2.22.1.jar。 我已经通过从 WEB-INF / lib 删除所有jar并从maven添加它来解决了这个问题。

答案 1 :(得分:3)

确保使用相同版本的球衣客户端,服务器和公共图书馆(例如2.22.1)

答案 2 :(得分:1)

明确包含这个库解决了问题

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

答案 3 :(得分:0)

删除分段文件上传的依赖项