【发布时间】:2011-10-03 11:12:58
【问题描述】:
我想在我的网络应用程序中使用 REST 服务(.war 和 6.0.0.Final),并且最近从 jersey 切换到了 resteasy(因为 JBoss6 with REST client (jersey-client))。
我的客户端代码就是这个简单的例子(从控制台调用时完美运行):
ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
RegisterBuiltin.register(providerFactory);
ClientRequest request = new ClientRequest(restUrl);
request.accept(MediaType.APPLICATION_XML);
ClientResponse<MyJaxbClass> response = request.get(MyJaxbClass.class);
一开始我希望 RESTeasy 的所有东西都可以在 JBoss 中使用,但是在访问该方法时我得到了这个错误:
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.jboss.resteasy.client.ClientRequest.createDefaultExecutorInstance(ClientRequest.java:115)
at org.jboss.resteasy.client.ClientRequest.getDefaultExecutor(ClientRequest.java:94)
at org.jboss.resteasy.client.ClientRequest.<init>(ClientRequest.java:125)
at my.own.MyRestEasyClient.members(MyRestEasyClient.java:42)
嗯,没什么大不了的!虽然我想知道为什么使用已弃用的commons-httpcomponents,但我将commons-httpclient:commons-httpclient:3.1 添加到我的.war 中。但是错误并没有消失。我仔细检查了commons-httpclient-3.1.jar 在战争中。然后我删除了 commons-httpcomponentsand addedorg.jboss.resteasy:resteasy-jaxrs:2.1.0.GAandorg.jboss.resteasy:resteasy-jaxb-provider:2.1.0.GA`。为了避免(也许我已经在)jar-hell,我使用了与 JBoss6 捆绑在一起的 resteasy-version,但现在我收到了这个错误:
Caused by: java.lang.annotation.AnnotationTypeMismatchException: Incorrectly
typed data found for annotation element public abstract
javax.xml.bind.annotation.XmlNsForm
org.jboss.xb.annotations.JBossXmlSchema.elementFormDefault()
(Found data of type Ljavax/xml/bind/annotation/XmlNsForm;.QUALIFIED)
这不是很具体,但是如果我将 jar 捆绑到 JBoss 中已经可用的 .war 中,我会遇到类似的错误。我找到了ClassNotFound Exception when configuring RestEasy,但这似乎与我的问题无关。
【问题讨论】: