Jersey error JAXBStringReaderProviders$RootElement

2019-04-10 02:03发布

问题:

17-53-2014 12:53:31.817 INFO - Registering com.citronium.fizionomizm.service.server.controllers.Root as a root resource class 17-53-2014 12:53:31.820 INFO - Registering com.citronium.fizionomizm.service.server.controllers.RecognizePath as a root resource class 17-53-2014 12:53:31.822 INFO - Initiating Jersey application, version 'Jersey: 1.18 11/22/2013 03:05 AM' 17-53-2014 12:53:31.929 ERROR - The provider class, class com.sun.jersey.server.impl.model.parameter.multivalued.JAXBStringReaderProviders$RootElementProvider, 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) ~[na:1.7.0_51] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_51] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_51] at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_51] at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:210) ~[fizionomizm-service.jar:0.1] at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:180) ~[fizionomizm-service.jar:0.1] at com.sun.jersey.core.spi.component.ProviderFactory._getComponentProvider(ProviderFactory.java:166) [fizionomizm-service.jar:0.1] at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:137) [fizionomizm-service.jar:0.1] at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:283) [fizionomizm-service.jar:0.1] at com.sun.jersey.core.spi.component.ProviderServices.getProvidersAndServices(ProviderServices.java:176) [fizionomizm-service.jar:0.1] at com.sun.jersey.server.impl.model.parameter.multivalued.StringReaderFactory.init(StringReaderFactory.java:60) [fizionomizm-service.jar:0.1] at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1341) [fizionomizm-service.jar:0.1] at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180) [fizionomizm-service.jar:0.1] at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799) [fizionomizm-service.jar:0.1] at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795) [fizionomizm-service.jar:0.1] at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) [fizionomizm-service.jar:0.1] at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) [fizionomizm-service.jar:0.1] at com.sun.jersey.guice.spi.container.servlet.GuiceContainer.initiate(GuiceContainer.java:121) [fizionomizm-service.jar:0.1] at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321) [fizionomizm-service.jar:0.1] at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) [fizionomizm-service.jar:0.1] at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) [fizionomizm-service.jar:0.1] at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376) [fizionomizm-service.jar:0.1] at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559) [fizionomizm-service.jar:0.1] at javax.servlet.GenericServlet.init(GenericServlet.java:244) [fizionomizm-service.jar:0.1] at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:119) [fizionomizm-service.jar:0.1] at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:84) [fizionomizm-service.jar:0.1] at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:104) [fizionomizm-service.jar:0.1] at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:224) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:810) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:743) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.server.Server.start(Server.java:355) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.server.Server.doStart(Server.java:324) [fizionomizm-service.jar:0.1] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [fizionomizm-service.jar:0.1] at com.citronium.fizionomizm.service.server.restserver.RESTServer.start(RESTServer.java:68) [fizionomizm-service.jar:0.1] at com.citronium.fizionomizm.service.Runner.main(Runner.java:19) [fizionomizm-service.jar:0.1] 17-53-2014 12:53:32.235 INFO - Binding com.citronium.fizionomizm.service.server.controllers.Root to GuiceManagedComponentProvider with the scope "Singleton" 17-53-2014 12:53:32.249 INFO - Binding com.citronium.fizionomizm.service.server.controllers.RecognizePath to GuiceManagedComponentProvider with the scope "Singleton" 17-53-2014 12:53:32.365 ERROR - The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for constructor public com.sun.jersey.server.impl.model.parameter.multivalued.JAXBStringReaderProviders$RootElementProvider(com.sun.jersey.spi.inject.Injectable,javax.ws.rs.ext.Providers) at parameter index 0 SEVERE: Method, public javax.ws.rs.core.Response com.citronium.fizionomizm.service.server.controllers.RecognizePath.upload(java.lang.String,java.lang.String) throws java.io.IOException, annotated with POST of resource, class com.citronium.fizionomizm.service.server.controllers.RecognizePath, is not recognized as valid resource method. SEVERE: Method, public javax.ws.rs.core.Response com.citronium.fizionomizm.service.server.controllers.RecognizePath.analyse(java.lang.String,java.lang.String), annotated with PUT of resource, class com.citronium.fizionomizm.service.server.controllers.RecognizePath, is not recognized as valid resource method. SEVERE: Method, public synchronized javax.ws.rs.core.Response com.sun.jersey.server.impl.wadl.WadlResource.geExternalGramar(javax.ws.rs.core.UriInfo,java.lang.String), annotated with GET of resource, class com.sun.jersey.server.impl.wadl.WadlResource, is not recognized as valid resource method. SEVERE: Method, public synchronized javax.ws.rs.core.Response com.sun.jersey.server.impl.wadl.WadlResource.getWadl(javax.ws.rs.core.Request,javax.ws.rs.core.UriInfo,javax.ws.rs.ext.Providers), annotated with GET of resource, class com.sun.jersey.server.impl.wadl.WadlResource, is not recognized as valid resource method. 17-53-2014 12:53:32.375 ERROR - Error while start server. com.sun.jersey.spi.inject.Errors$ErrorMessagesException at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) at com.sun.jersey.guice.spi.container.servlet.GuiceContainer.initiate(GuiceContainer.java:121) at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321) at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559) at javax.servlet.GenericServlet.init(GenericServlet.java:244) at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:119) at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:84) at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:104) at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:224) at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137) at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:810) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:743) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117) at org.eclipse.jetty.server.Server.start(Server.java:355) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) at org.eclipse.jetty.server.Server.doStart(Server.java:324) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) at com.citronium.fizionomizm.service.server.restserver.RESTServer.start(RESTServer.java:68) at com.citronium.fizionomizm.service.Runner.main(Runner.java:19)

This exception drop while start jar from console. If start from ide, work good.

回答1:

I realize this is old, but maybe someone else will find it useful.

In my case, this was caused by some conflicting service entries from different Jersey modules. The files in META-INF/services/ should be merged, but mine were being overwritten.

If you use the maven shade plugin, you can use ServicesResourceTransformer to easily merge service entries.