记一次关于springboot的netty版本冲突问题

 

冲突的地放其实很多,大概都是类似,找不到哪个方法了:

类似于:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
19/07/02 16:07:02 ERROR boot.SpringApplication: Application run failed
java.lang.NoSuchMethodError: io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(ILjava/util/concurrent/Executor;[Ljava/lang/Object;)V
        at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:52)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:87)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:82)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:63)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:51)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:43)
        at com.ime.gbt32960.InfoServerApplication.run(InfoServerApplication.java:33)
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:797)
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:781)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
        at com.ime.gbt32960.InfoServerApplication.main(InfoServerApplication.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)

其实发生这种事情,靠猜没用的。最简单粗暴的方式就是通过maven打印依赖树的方式,去查看;

比如上面的错误,是因为netty版本不一致造成的。那么就打印依赖树,找到所有netty。然后去掉不是你导入的版本就行了(因为应用的框架多了,内部通信啥的,很多都会选择netty,这就导致你的版本不一定与内部框架的netty版本一致的原因);

查看maven的依赖树方法:

 mvn dependency:tree 

然后搜索netty。就可以看到版本不一致是哪个框架的

如果知道了是哪个框架的,那么使用maven的排除,即可:

例如:

<dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>${hadoop.version}-${cdh.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.code.gson</groupId>
                    <artifactId>gson</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.netty</groupId>
                    <artifactId>netty</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.netty</groupId>
                    <artifactId>netty-all</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

 

posted @ 2019-07-02 16:29  niutao  阅读(9460)  评论(0编辑  收藏  举报