springboot与redis的结合问题

昨天改造项目,把redis模块分成一个子模块,发现了一个jar包问题

spring-boot-starter-data-redis与spring-boot-starter-redis的区别

spring-boot-starter-data-redis的依赖

  • 下图为spring-boot-starter-data-redis的依赖图


    spring-boot-starter-data-redis的依赖图.png
  • 看图会发现里面很多spring的重要包,但是为这个处于子模块,springboot项目也是一个子模块,然后依赖这个redis缓存模块,如果版本号不一样,这就会打包的时候会有很多包重复。

  • 下面是spring-boot-starter-data-redis的pom文件的依赖

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
    </dependencies>
  • spring-boot-starter-redis的依赖
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
    </dependencies>

可以看出两个包并没有区别,但是当springBoot的版本为1.4.7 以上的时候,spring-boot-starter-redis 就空了。要想引入redis就只能选择有data的。

  • 总结:
    1.如果不想很麻烦,直接引入spring-boot-starter-data-redis就可以了,如果类似我说的这种同为子模块,需要和springboot版本一致
    2.但是如果非要引入spring-boot-starter-redis,必须版本低于1.4.7以下,而且类似于我说的项目都是子模块,与spring版本不同时会出现引入spring某些包的多个版本
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容