JAX-RS:NoSuchMethodFound Exception Jersey-media-moxy JSON

时间:2016-01-22 02:02:16

标签: java jersey jax-rs moxy

我一直在努力工作几个小时。我正在用Jersey-RS制作球衣。一切都很顺利,直到我不得不在一个地方返回JSON。我知道必须有一个jersey-media-moxy库才能将Java对象绑定到JSON格式。我从Jersey-media-moxy到Google的genson库一个接一个地下载了几个JSON库。但还没有成功。使用我从http://www.java2s.com/Code/Jar/j/Downloadjerseymediamoxy23jar.htm下载的Jersey-media-moxy,运行Web服务时出现以下错误。

[2, 3, 1]

如果我用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) 更改 @Produces()注释,那么每件事都可以正常工作,但只要我将其更改为MediaType.APPLICATION_XML,我就会收到错误。

这是一个非maven项目,我通过Project-&gt;添加了罐子。属性。 我尝试了其他JSON库,如 Jetty,Jackson ,但没有一个工作过。 Jersey-media-moxy 以外的库会使 MessageBodyWriter找不到异常。我做错了什么?它与家属有关吗?这是我的项目结构:

Project Structure

在这方面的任何帮助将受到高度赞赏。 在此先感谢。

3 个答案:

答案 0 :(得分:1)

我一直遇到同样的问题,花了我很长时间才能摆脱掉。

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

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

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

答案 1 :(得分:0)

确保你的jersey.media jar与其他jersey jar完全相同

compile "org.glassfish.jersey.media:jersey-media-json-jackson:{$version}
所有罐子的

$ version应该是相同的

答案 2 :(得分:0)

就我而言,它的发生是由于:

<dependency>
    <groupId>org.glassfish.jersey.connectors</groupId>
    <artifactId>jersey-apache-connector</artifactId>
    <version>${jersey.version}</version>
</dependency>

其中 $ {jersey.version} 与其他球衣依赖项不同