问题描述
报错异常
1 | 2017-06-16 17:23:45,842 [RMI TCP Connection(3)-127.0.0.1] [6973a272f486418da8a37181a57ed0f9] INFO com.mangofactory.swagger.scanners.ApiListingReferenceScanner (ApiListingReferenceScanner.java:96) - Created resource listing Path: /default/test-token-controller Description: test-token-controller Position: 0 |
问题分析:
看到报错提示
1
2
3java.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:105)
at com.mangofactory.swagger.core.SwaggerApiResourceListing.initialize(SwaggerApiResourceListing.java:63)定位出错位置,确定锁依赖的 jar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19import com.google.common.collect.Multimaps;
public Map<ResourceGroup, List<RequestMappingContext>> getResourceGroupRequestMappings() {
return Multimaps.asMap(resourceGroupRequestMappings);
}
/**
* Returns {@link ListMultimap#asMap multimap.asMap()}, with its type
* corrected from {@code Map<K, Collection<V>>} to {@code Map<K, List<V>>}.
*
* @since 15.0
*/
@Beta
@SuppressWarnings("unchecked")
// safe by specification of ListMultimap.asMap()
public static <K, V> Map<K, List<V>> asMap(ListMultimap<K, V> multimap) {
return (Map<K, List<V>>) (Map<K, ?>) multimap.asMap();
}检查编译后的 war 中 libs 是否存在对应依赖的jar
冲突检查
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37E:\huanyuWorkSpace\huanyu\trunk {git}
{lamb} mvn dependency:tree -Dverbose -Dincludes=com.google.guava:guava
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.huanyu.huanyu:huanyu-web:war:0.1-SNAPSHOT
[WARNING] 'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-project-info-reports-plugin is missing. @ line 625, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Qianfan Shop Showwindow 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ huanyu-web ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.huanyu.huanyu:huanyu-web:war:0.1-SNAPSHOT
[INFO] +- com.github.binarywang:weixin-java-common:jar:2.6.0:compile
[INFO] | \- (com.google.guava:guava:jar:19.0:compile - omitted for duplicate)
[INFO] +- com.github.binarywang:weixin-java-mp:jar:2.6.0:compile
[INFO] | \- (com.google.guava:guava:jar:19.0:compile - omitted for duplicate)
[INFO] +- com.huanyu.dcommons:dcommons-token:jar:0.8:compile
[INFO] | \- (com.google.guava:guava:jar:19.0:compile - omitted for duplicate)
[INFO] +- com.mangofactory:swagger-models:jar:1.0.2:compile
[INFO] | \- (com.google.guava:guava:jar:15.0:compile - omitted for conflict with 19.0)
[INFO] +- com.mangofactory:swagger-springmvc:jar:1.0.2:compile
[INFO] | \- (com.google.guava:guava:jar:15.0:compile - omitted for conflict with 19.0)
[INFO] \- com.google.guava:guava:jar:19.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.946s
[INFO] Finished at: Fri Jun 16 18:10:57 CST 2017
[INFO] Final Memory: 22M/353M
[INFO] ------------------------------------------------------------------------使用 totalCommand 检查 jar 包,是一个行之有效的方法
1
2
3
4
5在 war 中的 libs 搜索 Multimaps.class 可以看到如下 jar 中都存在对应的 com\google\common\collect\Multimaps.class
E:\huanyuWorkSpace\huanyu\trunk\target\shouwin-web-0.1-SNAPSHOT\WEB-INF\lib\weld-osgi-bundle-1.0.1-SP3.jar/com\google\common\collect\Multimaps.class
E:\huanyuWorkSpace\huanyu\trunk\target\shouwin-web-0.1-SNAPSHOT\WEB-INF\lib\guava-19.0.jar/com\google\common\collect\Multimaps.class
E:\huanyuWorkSpace\huanyu\trunk\target\shouwin-web-0.1-SNAPSHOT\WEB-INF\lib\google-collections-1.0.jar/com\google\common\collect\Multimaps.class将 pom 中的对应的 jar 的依赖关系分列出来,清晰可见对应的依赖关系
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31E:\huanyuWorkSpace\huanyu\trunk {git}
{lamb} mvn dependency:tree -Dverbose -Dincludes=:google-collections
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.huanyu.huanyu:huanyu-web:war:0.1-SNAPSHOT
[WARNING] 'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-project-info-reports-plugin is missing. @ line 625, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Qianfan Shop Showwindow 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ huanyu-web ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
[INFO] com.huanyu.huanyu:huanyu-web:war:0.1-SNAPSHOT
[INFO] \- com.huanyu.lab:extapi:jar:1.1.4:compile
[INFO] \- org.jboss.weld:weld-osgi-bundle:jar:1.0.1-SP3:compile
[INFO] +- org.jboss.weld:weld-core:jar:1.0.1-SP3:compile
[INFO] | \- (com.google.collections:google-collections:jar:1.0:compile - omitted for duplicate)
[INFO] \- com.google.collections:google-collections:jar:1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.976s
[INFO] Finished at: Fri Jun 16 17:24:30 CST 2017
[INFO] Final Memory: 22M/353M
[INFO] ------------------------------------------------------------------------排除对应依赖即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35从 6 中可以看到
[INFO] com.huanyu.huanyu:huanyu-web:war:0.1-SNAPSHOT
[INFO] \- com.huanyu.lab:extapi:jar:1.1.4:compile
[INFO] \- org.jboss.weld:weld-osgi-bundle:jar:1.0.1-SP3:compile
[INFO] +- org.jboss.weld:weld-core:jar:1.0.1-SP3:compile
[INFO] | \- (com.google.collections:google-collections:jar:1.0:compile - omitted for duplicate)
[INFO] \- com.google.collections:google-collections:jar:1.0:compile
因此 排除 weld-osgi-bundle 即可。
<dependency>
<groupId>com.huanyu.lab</groupId>
<artifactId>extapi</artifactId>
<version>${extapi.version}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-osgi-bundle</artifactId>
</exclusion>
</exclusions>
</dependency>
maven pom 依赖检查:
mvn 命令
- mvn dependency:analyze
- mvn dependency:tree
- mvn dependency:tree
- mvn dependency:tree -Dverbose 简单地用dependency:tree往往并不能查看到所有的传递依赖。不过如果你真的想要看所有的,必须得加一个-Dverbose参数,这时就必定是最全的了
- mvn dependency:tree -Dincludes 加上Dincludes或者Dexcludes,dependency:tree就会帮你过滤出来; 例如: Dincludes=org.springframework:spring-tx ;过滤串使用groupId:artifactId:version的方式进行过滤,可以不写全
使用示例:
mvn dependency:tree -Dverbose -Dincludes=com.google.guava:guava
1 | [INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ shouwin-web --- |