spring boot redis和netty5.0.0冲突

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>5.0.0.Alpha1</version>
        </dependency>

启动的时候会出现如下错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method io.netty.bootstrap.Bootstrap.channel(Ljava/lang/Class;)Lio/netty/bootstrap/Bootstrap; but it does not exist. Its class, io.netty.bootstrap.Bootstrap, is available from the following locations:

    jar:file:/F:/repository/io/netty/netty-transport/4.1.29.Final/netty-transport-4.1.29.Final.jar!/io/netty/bootstrap/Bootstrap.class
    jar:file:/F:/repository/io/netty/netty-all/5.0.0.Alpha1/netty-all-5.0.0.Alpha1.jar!/io/netty/bootstrap/Bootstrap.class

It was loaded from the following location:

    file:/F:/repository/io/netty/netty-transport/4.1.29.Final/netty-transport-4.1.29.Final.jar

问题分析:
spring-boot-starter-data-redis 引入了lettuce,
而lettuce又关联了

        <!-- Netty -->

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-common</artifactId>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport</artifactId>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-handler</artifactId>
        </dependency>

maven结构说明:
common模块引入的 spring-boot-starter-data-redis、netty-all
biz模块引入common模块
xxx模块,引入common模块、biz模块

解决思路:
xxx模块引入common模块时,排除lettuce-core即可!

        <dependency>
            <groupId>com.xxx.xxx</groupId>
            <artifactId>common</artifactId>
             <exclusions>
                 <exclusion>
                     <groupId>io.lettuce</groupId>
                     <artifactId>lettuce-core</artifactId>
                 </exclusion>
             </exclusions>
        </dependency>
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐