1

I was able to run my Spring MVC appication, until the point where I introduced swagger dependency for the API documentation.

Now when I run the application in jetty server[Run as -> Run Jetty], I get the below error

java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.asMap(Lcom/google/common/collect/ListMultimap;)Ljava/util/Map;
    at com.mangofactory.swagger.scanners.ApiListingReferenceScanner.getResourceGroupRequestMappings(ApiListingReferenceScanner.java:146)

Searching the web, I see comments on upgrading the com.google.guava to 15.0 version, but still the issue persists.

Changes made that triggered the error: pom.xml:

<dependency>
  <groupId>com.mangofactory</groupId>
  <artifactId>swagger-springmvc</artifactId>
  <version>0.8.8</version>
</dependency>

and the SwaggerConfig.java for Enabling swagger as mentioned here : http://java.dzone.com/articles/how-configure-swagger-generate

I'm stuck, please help

Update: Running in tomcat, but not in jetty

Update [11/11]:

  1. upgraded swagger version to 0.9.1
  2. upgraded guava version to 18.0
  3. mvn dependency:tree shows only one guava version

    com.google.guava:guava:jar:18.0:compile

Even now the same issue exists!

spiderman
  • 10,892
  • 12
  • 50
  • 84

2 Answers2

2

You might have multiple Guava dependencies on your classpath, in which case the Multimaps class from Guava 15.0 might be "hidden" by the Multimaps class from an earlier Guava version (or even Google Collections version).

You should run mvn dependency:tree to see if Guava 15.0 is the only Guava dependency, or if other versions are included (usually by transitive dependencies from some other library).

If you find such dependencies, you should exclude them in your pom.xml.

Remark: if those libraries where depending on classes and/or methods that were removed in Guava 15.0, you might need to upgrade them instead. But it shouldn't happen if they stay away from @Beta APIs, as they should.


Edit:

Since it doesn't seem to be a dependency conflict according to your output of mvn dependency:tree, maybe it's related to this issue, where Glassfish was bundling a different version of Guava? You are not using Glassfish, but it might be worth looking at the dependencies your App Server might be adding to the classpath.

More info: - https://code.google.com/p/guava-libraries/issues/detail?id=1668 - https://java.net/jira/browse/GLASSFISH-20850

Community
  • 1
  • 1
Etienne Neveu
  • 12,604
  • 9
  • 36
  • 59
  • 1
    Thank you, I will analyze and come back with the dependency tree. I remember I checked for this in Dependency hierarchy in pom.xml on Eclipse IDE. But lemme check again – spiderman Nov 08 '14 at 20:30
  • 1
    The mvn dependency:tree showed up only one guava version. Please see my update in the post – spiderman Nov 11 '14 at 15:57
  • Thank you for that, unfortunately I cant do another +1 :).. I will accept as answer once I find the same for jetty. Thank you Etienne – spiderman Nov 11 '14 at 22:42
0

I'm sorry to add to such an old post, but two years later I got stuck on the same problem. It seems that the swagger-webmvc references dependencies that are not listed in the maven dependency tree. This might be because this project (and its successor springfox-swagger2) internally use Gradle instead of Maven.

The solution that helped me was adding the following exclusion for guava to (my two) springfox dependencies:

<exclusions>
      <exclusion>
               <groupId>com.google.guava</groupId>
               <artifactId>guava</artifactId>
      </exclusion>
</exclusions>
user3401125
  • 1
  • 2
  • 2