Jersey REST 服务调用另一个 Jersey REST 服务时出错 - java.lang.IllegalArgumentException:参数类型不匹配
Posted
技术标签:
【中文标题】Jersey REST 服务调用另一个 Jersey REST 服务时出错 - java.lang.IllegalArgumentException:参数类型不匹配【英文标题】:Error while Jersey REST service calling another Jersey REST service - java.lang.IllegalArgumentException: argument type mismatch 【发布时间】:2014-03-16 06:21:00 【问题描述】:从另一个 Jersey REST 服务调用一个 Jersey REST 服务时出现以下错误。两者都部署在不同的 tomcats 上。被调用服务在 Jersey 版本 1.16 上运行,调用服务在 1.4 上运行 当我使用 Grizzly 服务器在本地机器上部署调用服务时,一切正常,但是当我将其部署到 tomcat 上时,我遇到了这个问题。
SEVERE: The provider class, class com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General, could not be instantiated. Processing will continue but the class will not be utilized
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.sun.jersey.core.spi.component.ComponentConstructor._getInstance(ComponentConstructor.java:198)
at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:169)
at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:166)
at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:137)
at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:256)
at com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:160)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initWriters(MessageBodyFactory.java:207)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:163)
at com.sun.jersey.api.client.Client.init(Client.java:326)
at com.sun.jersey.api.client.Client.access$000(Client.java:118)
at com.sun.jersey.api.client.Client$1.f(Client.java:189)
at com.sun.jersey.api.client.Client$1.f(Client.java:185)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:197)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.<init>(Client.java:168)
at com.sun.jersey.api.client.Client.create(Client.java:638)
...
Loaded com.sun.jersey.client.urlconnection.HttpURLConnectionFactory from file:/fmrkut3/apps/UAT3/venture/lib/jersey-client-1.4.jar]
[Loaded com.sun.jersey.api.client.ClientRequest from file:/fmrkut3/apps/UAT3/venture/lib/jersey-client-1.4.jar]
Feb 17, 2014 4:15:08 AM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.xml.SAXParserContextProvider(com.sun.jersey.core.util.FeaturesAndProperties) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.xml.XMLStreamReaderContextProvider(com.sun.jersey.core.util.FeaturesAndProperties) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.xml.DocumentBuilderFactoryProvider(com.sun.jersey.core.util.FeaturesAndProperties) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.xml.TransformerFactoryProvider(com.sun.jersey.core.util.FeaturesAndProperties) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$Text(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$Text(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$Text(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0
SEVERE: Missing dependency for constructor public com.sun.jersey.core.impl.provider.entity.DocumentProvider(com.sun.jersey.spi.inject.Injectable,com.sun.jersey.spi.inject.Injectable) at parameter index 0
【问题讨论】:
【参考方案1】:正如底部堆栈跟踪所暗示的,您缺少一个库;如果我没记错的话,是
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.16</version>
</dependency>
该库可能存在于您的本地配置中(或与 Grizzly 捆绑),而不是与 Tomcat。
【讨论】:
以上是关于Jersey REST 服务调用另一个 Jersey REST 服务时出错 - java.lang.IllegalArgumentException:参数类型不匹配的主要内容,如果未能解决你的问题,请参考以下文章
使用 ClientResponse Jersey 调用 Rest API
如何配置用于 Jersey REST 调用的最大并发线程数?
ajax 调用 jersey rest web 服务中的 Access-Control-Allow-Origin
如何在Java Jersey REST服务中强制使用queryparams?