spring boot redis和netty5.0.2冲突

今天用spring boot集成netty时候,刚开始挺顺利的,但是在引入

   
            org.springframework.boot
            spring-boot-starter-data-redis
        

之后,一切都变的不美好了,启动的时候会出现如下错误

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    io.lettuce.core.resource.DefaultEventLoopGroupProvider.createEventLoopGroup(DefaultEventLoopGroupProvider.java:141)

The following method did not exist:

    io.netty.util.concurrent.DefaultEventExecutorGroup.(ILjava/util/concurrent/ThreadFactory;)V

The method's class, io.netty.util.concurrent.DefaultEventExecutorGroup, is available from the following locations:

    jar:file:/C:/work/maven/mymaven/repo/io/netty/netty-all/5.0.0.Alpha2/netty-all-5.0.0.Alpha2.jar!/io/netty/util/concurrent/DefaultEventExecutorGroup.class
    jar:file:/C:/work/maven/mymaven/repo/io/netty/netty-common/4.1.45.Final/netty-common-4.1.45.Final.jar!/io/netty/util/concurrent/DefaultEventExecutorGroup.class

It was loaded from the following location:

    file:/C:/work/maven/mymaven/repo/io/netty/netty-all/5.0.0.Alpha2/netty-all-5.0.0.Alpha2.jar

刚开始看的时候一脸懵逼的,我这里也没有隐去netty4.1.45的版本,因为netty4和netty5的差别还是蛮的,往上一看,是lettuce的问题,lettuce不用说肯定是redis引入的,然后发现redis果然引入了



    io.lettuce
    lettuce-core
    5.1.8.RELEASE

而lettuce又关联了

       
            io.netty
            netty-common
        
        
            io.netty
            netty-handler
        
        
            io.netty
            netty-transport
        

出现这种情况我第一反应是屏蔽,然后强制的指定版本。

第一次的做法是直接屏蔽lettuce

        
            org.springframework.boot
            spring-boot-starter-data-redis
            
                
                    io.netty
                    lettuce-core
                
            
        

这样是解决了上面的问题,但是导致了redis无法完成bean注入,出现RedisConnectFactory找不到的情况,所以直接放弃,改用下面的屏蔽方法。 

  
        
            io.netty
            netty-common
            5.0.0.Alpha2
        
        
            io.netty
            netty-handler
            5.0.0.Alpha2
        
        
            io.netty
            netty-transport
            5.0.0.Alpha2
        
        
        
            org.springframework.boot
            spring-boot-starter-data-redis
            
                
                    io.netty
                    netty-common
                
                
                    io.netty
                    netty-handler
                
                
                    io.netty
                    netty-transport
                
            
        

然并卵,问题依旧没解决,最后没办法了,我就只能降低netty的版本了。



    io.netty
    netty-all
    4.1.45.Final

和lettuce-core的版本中的netty版本保持一致,问题解决。其实还是蛮坑的,毕竟netty4和netty5的代码实现还是有很大的差别的,只能去改动一下实现代码了

你可能感兴趣的:(netty)