Glassfish 中的 ResteasyProviderFactory 异常
我在使用 RESTEasy 提供的客户端框架调用 RESTful Web 服务时遇到一些问题。当我尝试注册 ResteasyProviderFactory 时,我收到了 ClassCastException 并且没有其他任何作用。
代码如下:
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
LifeGoalClient leClient = ProxyFactory.create(LifeGoalClient.class, "http://localhost:8080/TutorFinanceiro");
List<LifeGoal> lifeGoals = leClient.getLifeGoals();
JOptionPane.showMessageDialog(null, lifeGoals);
return lifeGoals;
例外情况:
java.lang.ClassCastException: com.sun.jersey.server.impl.provider.RuntimeDelegateImpl cannot be cast to org.jboss.resteasy.spi.ResteasyProviderFactory
我使用的是 Glassfish 3.0.1 和 Resteasy 2.2.1。
我在网上搜索但没有找到解决方案或没有与此相关的信息。 如果有人有解决方案或替代方法,请帮助我!
提前致谢
I'm having some trouble invoking a RESTful webservice using the Client Framework provided by RESTEasy. When I try to register the ResteasyProviderFactory I got a ClassCastException and nothing more works.
Here's the code:
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
LifeGoalClient leClient = ProxyFactory.create(LifeGoalClient.class, "http://localhost:8080/TutorFinanceiro");
List<LifeGoal> lifeGoals = leClient.getLifeGoals();
JOptionPane.showMessageDialog(null, lifeGoals);
return lifeGoals;
And the exception:
java.lang.ClassCastException: com.sun.jersey.server.impl.provider.RuntimeDelegateImpl cannot be cast to org.jboss.resteasy.spi.ResteasyProviderFactory
I'm using Glassfish 3.0.1 and Resteasy 2.2.1.
I searched through the web but found no solution or no relevant info in respect to this.
If anyone have a solution or an alternative way of doing this, please help me!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我确实通过在“META-INF/services”的类路径中添加一个名为 javax.ws.rs.ext.RuntimeDelegate 的文件来强制在 glassfish 中的 jersey 上实现 Resteasy,该文件仅包含以下行:
org.jboss.resteasy.spi.ResteasyProviderFactory
然而,对我来说,一切似乎都工作正常,直到我尝试使用resteasy-cdi。将最后一个工件添加到我的依赖项并配置所需的上下文参数确实发现了相同的类广播问题。
I did force resteasy over jersey in glassfish by adding a file named javax.ws.rs.ext.RuntimeDelegate in the class path at "META-INF/services", wich contain only the following line :
org.jboss.resteasy.spi.ResteasyProviderFactory
However, for me, all seemed to work fine until I try to use resteasy-cdi. Adding that last artifact to my dependencies and configuring the required context-param did dig up the same classcast problem.
这是由 jax-rs 实现 - jersey 和 Resteasy 冲突引起的。
为了防止上面的错误,你可以
在你的web.xml中添加。
通过这样做,resteasy 将选择 ResteasyProviderFactory 的实例。
This is caused by conflicting jax-rs implementation - jersey and resteasy.
In order to prevent the error above, you can add
in your web.xml.
By doing so, resteasy will choose instance of ResteasyProviderFactory.