gpt4 book ai didi

java - JAX-RS:NoSuchMethodFound 异常 Jersey-media-moxy JSON

转载 作者:行者123 更新时间:2023-12-01 22:51:47 25 4
gpt4 key购买 nike

我已经为此苦苦挣扎了几个小时。我正在使用 jersey 开发 JAX-RS。一切都很顺利,直到我不得不在一处返回 JSON。我知道必须有一个 jersey-media-moxy 库才能将 Java 对象绑定(bind)到 JSON 格式。我从 Jersey-media-moxy 到 Google 的 genson 库,陆续下载了几个 JSON 库。但还没有成功。使用我从 http://www.java2s.com/Code/Jar/j/Downloadjerseymediamoxy23jar.htm 下载的 Jersey-media-moxy ,我在运行 Web 服务时收到以下错误。

SEVERE: StandardWrapper.Throwable
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:67)
at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:714)
at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:644)
at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:829)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:453)
at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
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.processWithException(Errors.java:255)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:172)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:364)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Jan 22, 2016 6:44:46 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet JAVA WS
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.util.PropertiesHelper.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
at org.glassfish.jersey.moxy.json.MoxyJsonFeature.configure(MoxyJsonFeature.java:67)
at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:714)
at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:644)
at org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:829)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:453)
at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
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.processWithException(Errors.java:255)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:172)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:364)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

如果我使用 MediaType.APPLICATION_XML 更改 @Produces() 注释,一切都会正常工作,但一旦我将其更改为 MediaType.APPLICATION_JSON,我收到错误。

这是一个非 Maven 项目,我通过“项目”->“属性”添加了 jar。我尝试了其他 JSON 库,例如 Jetty、Jackson,但没有一个有效。 Jersey-media-moxy 之外的库会引发 MessageBodyWriter not found 异常。我做错了什么?与依赖有关吗?这是我的项目结构:

Project Structure

在这方面的任何帮助将不胜感激。提前致谢。

最佳答案

我也遇到过同样的问题,花了很长时间才解决。

此问题的基本问题是缺少 jersey-media-moxy-2.27.jar 请求的几个 jarjersey-media-moxy-2.27 jar 内部使用了一些运行时所需的更多 API。

要解决此问题,请参阅随附的快照并确保您的项目中拥有所有 jar(版本很重要) image

建议:如果您使用 Eclipse IDE,认为服务器已“启动”,请尝试在启动服务器(在我的例子中是 Tomcat)时查看控制台日志。不应该有任何错误消息。

关于java - JAX-RS:NoSuchMethodFound 异常 Jersey-media-moxy JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34937793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com