Jersey: “Missing dependency for method …”

2019-05-06 04:35发布

问题:

Could somebody please explain the meaning of this error?

INFO: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
Feb 21, 2012 3:03:48 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class com.foo.dom2jcr.rest.XMLCRUDRestlet
Feb 21, 2012 3:03:48 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Feb 21, 2012 3:03:48 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
Feb 21, 2012 3:03:49 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 method public void com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.json.impl.provider.entity.JSONListElementProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.json.impl.provider.entity.JSONListElementProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
  SEVERE: Missing dependency for method public void com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(com.sun.jersey.core.util.FeaturesAndProperties) at parameter at index 0
[INFO] Started Jetty Server

I am using Jersey 1.11 + Jetty 7.6.1.v20120215. These are my dependencies:

                <dependency>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-bundle</artifactId>
                    <version>1.11</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-client</artifactId>
                    <version>1.11</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.jersey</groupId>
                    <artifactId>jersey-servlet</artifactId>
                    <version>1.11</version>
                </dependency>
                <dependency>
                   <groupId>com.sun.jersey.contribs</groupId>
                   <artifactId>jersey-multipart</artifactId>
                   <version>1.11</version>
                </dependency>

I tried looking around Google, but I couldn't seem to find the cause.

Thanks in advance!

回答1:

remove

   <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-bundle</artifactId>
        <version>1.11</version>
   </dependency>

and you should be fine.

You are confusing Jersey by adding bundle and separate dependencies to the classpath. So basically you have two classes which have same name ("com.sun.jersey.core.util.FeaturesAndProperties" in this case), Jersey runtime expects one and you are providing second one.. or vice versa.

Anyway, you should be fine when jersey-bundle is removed from classpath.



回答2:

I had experienced similar issue while dealing with multipart uploads. After bit searching and investigation, I figured out that I was using different version of jersey-multipart and mimepull jars which were not compatible with the jersey bundle used in my project.

If you are a non-maven developer, make sure that you have added following jars in your classpath:

  • jersey-multipart-X.jar
  • mimepull-Y.jar

X and Y are version identifiers for jersey-multipart and mimepull jars respectively.

*Note that X (version of jersey-multipart) should be same as the version of jersey-bundle jar.