我想在我的web應用中使用REST服務(.war with 6.0.0.Final),並且最近從澤西轉換到resteasy(因爲JBoss6 with REST client (jersey-client))。帶有RestEasy客戶端的JBoss6
我的客戶端代碼是這個簡單的例子(完美的工作從控制檯調用時):
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
,但我在.war中添加了commons-httpclient:commons-httpclient:3.1
。但錯誤沒有消失。我仔細檢查commons-httpclient-3.1.jar
是在戰爭中。然後我刪除了commons-httpcomponents and added
org.jboss.resteasy:resteasy-jaxrs:2.1.0.GA and
org.jboss.resteasy:resteasy-jaxb-provider:2.1.0.GA`。爲了避免(也許我已經在)JAR-地獄我用它是捆綁在一起的JBoss6 RestEasy的版本,但現在我得到這個錯誤:
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)
這是不是真的specifict,但我得到了類似的如果我將jar包裝到我的.war中,那麼這些錯誤在JBoss中已經可用。我發現ClassNotFound Exception when configuring RestEasy,但這似乎與我的問題沒有關係。