升级 Jersey 版本后随机 REST API 调用失败

Random REST API calls fail after upgrading Jersey version

最近不得不将 Jersey 的版本从 2.5.1(原因稍后解释)升级到 2.7,自从升级后,每次我将代码上传到服务器时,随机 API 调用开始失败并出现以下问题堆栈跟踪:

org.glassfish.jersey.internal.Errors logErrors: The following warnings have been detected: WARNING: HK2 service reification failed for [com.example.rest.LeaderboardApi] with an exception:
MultiException stack 1 of 2
java.lang.NullPointerException
        at org.jvnet.hk2.internal.Utilities.hasInjectAnnotation(Utilities.java:1484)
        at org.jvnet.hk2.internal.Utilities.findInitializerMethods(Utilities.java:1425)
        at org.jvnet.hk2.internal.DefaultClassAnalyzer.getInitializerMethods(DefaultClassAnalyzer.java:102)
        at org.glassfish.jersey.internal.inject.JerseyClassAnalyzer.getInitializerMethods(JerseyClassAnalyzer.java:239)
        at org.jvnet.hk2.internal.Utilities.getInitMethods(Utilities.java:243)
        at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:163)
        at org.jvnet.hk2.internal.ClazzCreator.initialize(ClazzCreator.java:200)
        at org.jvnet.hk2.internal.SystemDescriptor.internalReify(SystemDescriptor.java:649)
        at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:604)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:405)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2046)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.access0(ServiceLocatorImpl.java:116)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.compute(ServiceLocatorImpl.java:1011)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.compute(ServiceLocatorImpl.java:1006)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.call(LRUHybridCache.java:115)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.call(LRUHybridCache.java:111)
        at java.util.concurrent.FutureTask.run(FutureTask.java:260)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.run(LRUHybridCache.java:173)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache.compute(LRUHybridCache.java:292)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetDescriptor(ServiceLocatorImpl.java:1093)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:616)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:606)
        at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:173)
        at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
        at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:94)
        at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:63)
        at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
        at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:261)
        at org.glassfish.jersey.internal.Errors.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:252)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1023)
        at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
        at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:535)
        at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:483)
        at com.example.config.JerseyFilter.doFilter(JerseyFilter.java:27)
        at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:420)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
        at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
        at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
        at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.call(AbstractShiroFilter.java:365)
        at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
        at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
        at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
        at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:257)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:326)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
        at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
        at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:657)
        at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:619)
        at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:589)
        at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:453)
        at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:460)
        at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:293)
        at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:319)
        at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:311)
        at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:457)
        at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:263)
        at java.lang.Thread.run(Thread.java:745)

MultiException stack 2 of 2
java.lang.IllegalArgumentException: Errors were discovered while reifying SystemDescriptor(
        implementation=com.example.rest.LeaderboardApi
        contracts={com.example.rest.LeaderboardApi}
        scope=org.glassfish.jersey.process.internal.RequestScoped
        qualifiers={}
        descriptorType=CLASS
        descriptorVisibility=NORMAL
        metadata=
        rank=0
        loader=null
        proxiable=null
        proxyForSameScope=null
        analysisName=null
        id=156
        locatorId=0
        identityHashCode=1367521629
        reified=false)
        at org.jvnet.hk2.internal.SystemDescriptor.reify(SystemDescriptor.java:615)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.reifyDescriptor(ServiceLocatorImpl.java:405)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.narrow(ServiceLocatorImpl.java:2046)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.access0(ServiceLocatorImpl.java:116)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.compute(ServiceLocatorImpl.java:1011)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.compute(ServiceLocatorImpl.java:1006)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.call(LRUHybridCache.java:115)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.call(LRUHybridCache.java:111)
        at java.util.concurrent.FutureTask.run(FutureTask.java:260)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache$OriginThreadAwareFuture.run(LRUHybridCache.java:173)
        at org.glassfish.hk2.utilities.cache.LRUHybridCache.compute(LRUHybridCache.java:292)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetDescriptor(ServiceLocatorImpl.java:1093)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:616)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:606)
        at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:173)
        at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
        at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:115)
        at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:94)
        at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:63)
        at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
        at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:261)
        at org.glassfish.jersey.internal.Errors.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
        at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:252)
        at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1023)
        at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
        at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
        at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:535)
        at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:483)
        at com.example.config.JerseyFilter.doFilter(JerseyFilter.java:27)
        at org.glassfish.jersey.servlet.ServletContainer.doFilter(ServletContainer.java:420)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
        at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
        at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
        at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.call(AbstractShiroFilter.java:365)
        at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
        at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
        at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:37)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
        at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:257)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:326)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
        at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
        at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:657)
        at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:619)
        at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:589)
        at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:453)
        at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:460)
        at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:293)
        at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:319)
        at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:311)
        at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:457)
        at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:263)
        at java.lang.Thread.run(Thread.java:745)

每次我进行干净的构建并重新上传时,一组新的方法开始失败(并且之前失败的方法开始工作)而无需任何代码更改!

在尝试 2.7 之后,我切换到 2.25.1,这又打开了另一个蠕虫罐头,所以我尝试使用 2.5.2(而不是原来的 2.5.1),它和 2.5 有同样的问题.1.我切换到 2.8,它有与 2.7 相同的随机问题。

目前的状态是,无论是版本 2.7 还是 2.8,REST API 方法的一个小的(至少看起来)随机子集失败并显示与上述类似的消息。

我想找出原因并修复它。

切换球衣版本时遵循的方法

我会清理 /WEB-INF/lib 文件夹,将 pom.xml 中的 jersey.version 变量更改为新版本。然后 Eclipse 将获取所有必要的库并重新构建代码。 运行 mvn appengine:update 将重新填充 /WEB-INF/lib 文件夹并将所有内容打包。

我做了几次干净(完整)的构建,以确保不会混合来自不同版本的人工制品。

从 2.5.1 升级的原因

必须添加一个方法(具有以下签名):

public Response importChildren(@Context ContainerRequestContext reqCtx,
        @PathParam(ID) String id, @FormDataParam("file") InputStream csvStream,
        @FormDataParam("test") String testStr)

这将需要一个 CSV 文件的 InputStream 并对其进行处理。因此必须添加 jersey-media-multipart。与版本 2.5.x 一起使用(未尝试使用 2.6),这开始出错,因为它试图将 InputStream 写入临时文件(在 [=55= 中禁止写入磁盘) ] App Engine (Standard),这是我正在使用的。

对于 >= 2.7 的版本,可以通过添加内容为 jersey.config.multipart.bufferThreshold = -1

的文件 jersey-multipart-config.properties 来避免这种写入临时文件的趋势

绝望的解决方法

如果没有别的办法,我可以将 CSV 处理代码从 Jersey 介导的方法中移出并移到一个简单的 servlet 中。然后我不需要 jersey-media-multipart 并且可以回到使用版本 2.5.1,所有代码都可以可靠地工作。

这个

java.lang.NullPointerException
    at org.jvnet.hk2.internal.Utilities.hasInjectAnnotation(Utilities.java:1484)

是 Jersey 和特定底层 HK2 内核版本之间的互操作 known bug,它附带 Jersey 2.7 作为传递依赖

We've switched to HK2 2.3.0-b05 in 2.9-SNAPSHOT. After we release 2.9 the problem should be gone.

看起来最近修复了该错误的 Jersey 版本是 2.9。但如果您更愿意继续使用 2.7,请找到以下解决方法。

通过 Maven 强制使用 hk2-api 2.3.0-b05 版本:

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.7</version>
    <exclusions>
        <exclusion>
            <groupId>org.glassfish.hk2</groupId>
            <artifactId>hk2-api</artifactId>
            <!-- this is to exclude 2.2.0 version -->
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.glassfish.hk2</groupId>
    <artifactId>hk2-api</artifactId>
    <version>2.3.0-b05</version>
</dependency>

您 pom.xml 中的一些其他 Jersey 工件可能需要排除练习,只需相应地检查 mvn dependency:tree ...

完整的解决方案

by @Kostiantyn 让我走上了正确的道路,尽管我必须做一些小的改变才能让它工作。为了让其他人可以避免我不得不面对的时间浪费,我将在下面给出完整的解决方案。

正如@Kostiantyn 指出的那样,我需要升级到 Jersey 2.9 以消除 Jersey 和 HK2 之间的互操作错误。但是,当我切换到 2.9 时,我开始在所有 POST/PUT 方法(所有这些 @Consumes(MediaType.APPLICATION_JSON):

上收到以下错误
org.glassfish.jersey.message.internal.ReaderInterceptorExecu‌​tor$TerminalReaderIn‌​terceptor aroundReadFrom:
  MessageBodyReader not found for media type=application/json, type=class com.example.json.StarDto,
    genericType=class com.example.json.StarDto

这是个大问题,为了解决这个问题,我添加了以下依赖项(根据@Kostiantyn 的建议):

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

使用这个新添加的依赖项进行测试后,旧的错误消失了,相反我开始在我的 POST 方法(没有测试 PUT 方法)中得到以下信息:

org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError:
  com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase.<init>(Lc‌​om/fasterxml/jackson‌​/databind/cfg/Mapper‌​Config;

在尝试了很多不同的事情之后,我终于意识到 jersey-media-json-jackson 正在引入 jackson-jaxrs-base-2.3.2.jar,这与 jackson-jaxrs-base-2.7.1.jar(这是我需要的版本)。所以添加 jersey-media-json-jackson 并排除以下内容终于解决了我所有的问题:

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.version}</version>
        <scope>runtime</scope>
        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-base</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

尝试将我的应用程序部署到 weblogic 服务器时遇到完全相同的问题。

重新启动 weblogic 托管服务器对我有用

停止:

通过在 Web 浏览器的 URL 行中键入 http://[host name]:[port]/console 来启动 WebLogic Server 管理控制台。

在“域结构”下,单击“环境”>“服务器”。

在右窗格中,单击“控制”选项卡。

Select 您要停止的托管服务器。

单击要停止的托管服务器下方的关闭按钮。

Select 当工作完成时正常关闭服务器或 select 立即强制关闭立即停止服务器而不完成正在进行的任务。

在“服务器生命周期助手”窗格中,单击“是”完成关闭。

开始:

确保 WebLogic Server 和节点管理器 运行。

通过在 Web 浏览器的 URL 行中键入 http://[host name]:[port]/console 来启动 WebLogic Server 管理控制台。

在“域结构”下,单击“环境”>“服务器”。

在右窗格中,单击“控制”选项卡。

Select 您要启动的托管服务器。

单击要启动的托管服务器下方的“启动”按钮。