本文已参与「新人创作礼」活动,一起开启掘金创作之路。
jar包冲突的解决
ES 9300 Netty jar冲突
问题
[2020-01-13T16:12:24,691][WARN ][o.e.t.n.Netty4Transport ] [yq1] send message failed [channel: NettyTcpChannel{localAddress=0.0.0.0/0.0.0.0:9300, remoteAddress=/192.168.251.205:50072}]
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[?:?]
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[?:?]
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[?:?]
at sun.nio.ch.IOUtil.write(IOUtil.java:51) ~[?:?]
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471) ~[?:?]
at io.netty.channel.socket.nio.NioSocketChannel.doWrite(NioSocketChannel.java:388) ~[netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0(AbstractChannel.java:934) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.forceFlush(AbstractNioChannel.java:368) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:639) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:545) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [netty-transport-4.1.16.Final.jar:4.1.16.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-common-4.1.16.Final.jar:4.1.16.Final]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_112]
原因
发现是netty相关问题,查看程序pom文件中的netty依赖版本如下
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.38.Final</version>
</dependency>
</dependencies>
</dependencyManagement>
错误中提示netty版本为4.1.16.Final,与依赖中版本不一致
解决办法
把pom文件中依赖注释掉
IDEA spring boot maven项目中对接swagger jar冲突解决思路
问题
***************************\
APPLICATION FAILED TO START\
***************************
Description:
An attempt was made to call the method com.google.common.collect.Multimaps.asMap(Lcom/google/common/collect/ListMultimap;)Ljava/util/Map; but it does not exist. Its class, com.google.common.collect.Multimaps, is available from the following locations:
jar:file:/opt/jzy/pytha-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/hive-exec-1.2.1.jar!/com/google/common/collect/Multimaps.class\
jar:file:/opt/jzy/pytha-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/guava-20.0.jar!/com/google/common/collect/Multimaps.class
It was loaded from the following location:
jar:file:/opt/jzy/pytha-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/hive-exec-1.2.1.jar!/
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.Multimaps
原因
1.一看就是jar冲突 首先想到的是pom文件中去掉hive-exec-1.2.1,但是我的pom文件中就没有依赖它,代码中也没有用到
于是使用idea中的project structure > Libraries 去掉hive-exec-1.2.1 再次运行还是报错,再次查看project structure > Libraries
hive-exec-1.2.1 依然存在,想着用修改pom文件中的方式解决。
2.查看hive-exec-1.2.1(guava16)中引用的guava版本与springfox-swagger2(guava20)中引用的guava版本区别很大,这个时候想到hive-exec-1.2.1,我根本没用,但是他还是加载,百度了一下说pom添加guava-20.0依赖,去掉其他的guava,试了一下还是报错。
3.查看springfox-swagger2引用时看到有个更新27.1-jre版本于是添加依赖,没有做排除如上面的依赖一样,但是还是做了idea中的project structure > Libraries 去掉hive-exec-1.2.1 再次运行没有问题了,再次查看project structure > Libraries hive-exec-1.2.1 不存在了
最终pom文件
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>27.1-jre</version> </dependency>