美文网首页
springboot与redis的结合问题

springboot与redis的结合问题

作者: 翔哥不哭 | 来源:发表于2019-01-18 16:22 被阅读0次

    昨天改造项目,把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某些包的多个版本

    相关文章

      网友评论

          本文标题:springboot与redis的结合问题

          本文链接:https://www.haomeiwen.com/subject/ahbndqtx.html