在 maven 构建的 JAR 中找不到 Jersey 消息正文阅读器
我的应用程序使用 REST (JAX-RS Jersey) 接口。当我在 Eclipse 中运行它时,一切都' 很好。域对象已注释,我没有使用 XML 文件进行 REST 映射。
现在,我使用 maven- assembly-plugin 创建了一个独立的 JAR,它将应用程序和所有依赖项打包在一个可执行的 JAR 文件中。这似乎也有效。
但是,当我启动应用程序并从服务器请求一个对象时,泽西岛抱怨它找不到消息正文阅读器:
com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java type, class de.rybu.atuin.core.entity.User, and MIME media type, application/json, was not found
有什么想法为什么会发生这种情况吗?
编辑:在我睡了一晚之后,我注意到它抱怨 JSON...但我只使用 XML 进行序列化。奇怪的。
My application uses a REST (JAX-RS Jersey) interface. When I run it in Eclipse, everything'
s fine. The domain objects are annotated, I'm not using XML files for the REST mapping.
Now I created a standalone JAR using the maven-assembly-plugin, which packs the application and all dependencies in a single, executable JAR file. This also seems to work.
But when I start the application and request an object from the server, Jersey complains, that it can't find a message body reader:
com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java type, class de.rybu.atuin.core.entity.User, and MIME media type, application/json, was not found
Any ideas why this happens?
EDIT: After I slept a night over it, I noticed that it complains about JSON... but I'm using only XML for serialization. Strange.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了同样的问题,在 stackoverflow 上搜索,我发现将 jersery-json-1.x.jar 添加到 WEB-INF/lib 中,就像 此解决方案将解决该问题。
请给Mikhail颁奖!
I run into the same issue, searching on stackoverflow, I found that adding jersery-json-1.x.jar into WEB-INF/lib like suggested by this solution will solve the issue.
Please give award to Mikhail!
我解决了这个问题,我想我知道怎么做:-)
我的资源是这样注释的:
我的客户使用了相反的顺序:
我不知道最初是什么导致了问题,但我完全删除了 JSON 支持,现在它可以工作了。也许在客户端中简单地交换 JSON 和 XML 的顺序就足够了,但我没有尝试这样做。
I fixed the problem and I guess I know how :-)
My resources were annotated like this:
My client used the reverse order:
I don't know what initially caused the problem but I completely removed JSON-support and now it works. Maybe it would have been sufficient to simply swith the order of JSON and XML in the client but I didn't try that.
我遇到了类似的问题(从 eclipse 运行正常,或者部署为单独的 jar,但不能从可执行 jar 部署),并发现 这种方法使用maven依赖插件创建可执行jar,maven jar插件工作正常。这是因为它将依赖项放在单独的 lib 目录中,然后将其包含在清单的类路径中,而不是将它们全部合并在一起,这可能会导致许多问题。
I ran into a similar problem (worked fine running from eclipse or deployed as separate jars but not from executable jar) and found that this approach for creating executable jars using the maven dependency plugin and maven jar plugin works properly. This is because it puts the dependencies in a separate lib directory and then includes that in the classpath in the manifest as opposed to merging them all together which can cause numerous issues.
我遇到了同样的问题(http://goo.gl/Mk9sZ)。通过将 jersey-multipart jar 的 Maven 依赖项从 1.0.2 更改为 1.8 版本解决了这个问题(在客户端和提供程序端使用相同的依赖项。
您可以在 http://goo.gl/Mk9sZ
I faced the same issue (http://goo.gl/Mk9sZ) . It got solved by changing maven dependency for jersey-multipart jar from 1.0.2 to 1.8 version (Used the same dependency in client side as well as provider side.
You can find the complete code I used at http://goo.gl/Mk9sZ
我正在使用 Jersey Client 1,为了解决这个问题,我创建了一个通用的 json 消息正文阅读器。
}
I am using Jersey Client 1 and to solve this problem, I created a generic json message body reader.
}