今天在springboot中使用数据库,springboot版本为2.0.2.RELEASE,通过pom引入jar包,配置文件application.properties中的redis配置文件报错,提示例如deprecated configuration property 'spring.redis.pool.max-active',猜想应该是版本不对,发现springboot在1.4前后集成redis发生了一些变化。下面截图看下。

一、不同版本RedisProperties的区别

这是springboot版本为1.3.2RELEASE中的RedisProperties配置文件类,从图片中可以看得出来该本的redis配置文件属性有两个内部静态类分别是Pool和Sentinel,七个属性变量。例如我们想在配置文件中设置redis数据库host地址,则可以这样写

spring.redis.host=localhost    host为属性,配置连接池的最大连接数 spring.redis.pool.max-active=8

这个是redis在application.properties中springboot低版本的配置

    1. # REDIS (RedisProperties)
      1. # Redis数据库索引(默认为0)
        1. spring.redis.database=0
          1. # Redis服务器地址
            1. spring.redis.host=localhost
              1. # Redis服务器连接端口
                1. spring.redis.port=6379
                  1. # Redis服务器连接密码(默认为空)
                    1. spring.redis.password=
                      1. # 连接池最大连接数(使用负值表示没有限制)
                        1. spring.redis.pool.max-active=8
                          1. # 连接池最大阻塞等待时间(使用负值表示没有限制)
                            1. spring.redis.pool.max-wait=-1
                              1. # 连接池中的最大空闲连接
                                1. spring.redis.pool.max-idle=8
                                  1. # 连接池中的最小空闲连接
                                    1. spring.redis.pool.min-idle=0
                                      1. # 连接超时时间(毫秒)
                                        1. spring.redis.timeout=0
                                      1.  

                                      下图则是springboot版本为2.0.2RELEASE中的RedisProperties配置文件类,从图中可知pool属性则被封装到了内部静态类Jedis和Lettuce中去了,这时我们要是配置连接池的最大连接数,前缀还是spring.redis,有两种途径

                                      spring.redis.jedis.pool.max-active=8  或者 spring.redis.lettuce.pool.max-active=8

                                      这个是redis在application.properties中springboot高版本的配置

                                        1. # REDIS (RedisProperties)
                                          1. # Redis数据库索引(默认为0)
                                            1. spring.redis.database=0
                                              1. # Redis服务器地址
                                                1. spring.redis.host=localhost
                                                  1. # Redis服务器连接端口
                                                    1. spring.redis.port=6379
                                                      1. # Redis服务器连接密码(默认为空)
                                                        1. spring.redis.password=
                                                          1. # 连接池最大连接数(使用负值表示没有限制)
                                                            1. spring.redis.jedis.pool.max-active=8
                                                              1. # 连接池最大阻塞等待时间(使用负值表示没有限制)
                                                                1. spring.redis.jedis.pool.max-wait=-1
                                                                  1. # 连接池中的最大空闲连接
                                                                    1. spring.redis.jedis.pool.max-idle=8
                                                                      1. # 连接池中的最小空闲连接
                                                                        1. spring.redis.jedis.pool.min-idle=0
                                                                          1. # 连接超时时间(毫秒)
                                                                            1. spring.redis.timeout=0
                                                                          1.  

                                                                          2、maven下pom中的坐标配置

                                                                          springboot版本1.4以下

                                                                            1. <!--引入 spring-boot-starter-redis(1.4版本前)-->
                                                                              1. <dependency>
                                                                                1. <groupId>org.springframework.boot</groupId>
                                                                                  1. <artifactId>spring-boot-starter-redis</artifactId>
                                                                                    1. <version>1.3.2.RELEASE</version>
                                                                                      1. </dependency>
                                                                                    1.  

                                                                                    springboot版本1.4以上

                                                                                    <!--引入 spring-boot-starter-data-redis(1.4版本后)多了个data加个红和粗吧-->

                                                                                      1. <dependency>
                                                                                        1. <groupId>org.springframework.boot</groupId>
                                                                                          1. <artifactId>spring-boot-starter-data-redis</artifactId>
                                                                                            1. </dependency>
                                                                                          1.  

                                                                                          原文地址:https://blog.csdn.net/qq_33326449/article/details/80457571

                                                                                          springboot中各个版本的redis配置问题的更多相关文章

                                                                                          1. SpringBoot中Shiro缓存使用Redis、Ehcache

                                                                                            在SpringBoot中Shiro缓存使用Redis.Ehcache实现的两种方式实例 SpringBoot 中配置redis作为session 缓存器. 让shiro引用 本文是建立在你是使用这sh ...

                                                                                          2. springboot中使用cache和redis

                                                                                            知识点:springboot中使用cache和redis (1)springboot中,整合了cache,我们只需要,在入口类上加 @EnableCaching 即可开启缓存 例如:在service层 ...

                                                                                          3. 在SpringBoot中存放session到Redis

                                                                                            前言 今天你们将再一次领略到SpringBoot的开发到底有多快,以及SpringBoot的思想(默认配置) 我们将使用redis存放用户的session,用户session存放策略有很多,有存放到内 ...

                                                                                          4. springboot 中 集成druid ,redis

                                                                                            1,导入druid jar包 <!--引入drud--> <dependency> <groupId>com.alibaba</groupId> < ...

                                                                                          5. springboot中,使用redisTemplate操作redis

                                                                                            知识点: springboot中整合redis springboot中redisTemplate的使用 redis存数据时,key出现乱码问题 一:springboot中整合redis (1)pom. ...

                                                                                          6. SpringBoot中整合Redis、Ehcache使用配置切换 并且整合到Shiro中

                                                                                            在SpringBoot中Shiro缓存使用Redis.Ehcache实现的两种方式实例 SpringBoot 中配置redis作为session 缓存器. 让shiro引用 本文是建立在你是使用这sh ...

                                                                                          7. 实例讲解Springboot以Repository方式整合Redis

                                                                                            1 简介 Redis是高性能的NoSQL数据库,经常作为缓存流行于各大互联网架构中.本文将介绍如何在Springboot中整合Spring Data Redis,使用Repository的方式操作. ...

                                                                                          8. 你知道如何在springboot中使用redis吗

                                                                                            特别说明:本文针对的是新版 spring boot 2.1.3,其 spring data 依赖为 spring-boot-starter-data-redis,且其默认连接池为 lettuce ​  ...

                                                                                          9. (二)Redis在Mac下的安装与SpringBoot中的配置

                                                                                            1 下载Redis 官网下载,下载 stable 版本,稳定版本. 2 本地安装 解压:tar zxvf redis-6.0.1.tar.gz 移动到: sudo mv redis-6.0.1 /us ...

                                                                                          随机推荐

                                                                                          1. html2canvas截取屏幕的方法

                                                                                            html2canvas截取屏幕的方法 需要放在服务上运行,否则会报错, 放在服务器里,完美运行  处理截屏模糊的方法 html2canvas 0.5.0-beta3解决截图模糊问题 需要引入html2 ...

                                                                                          2. 网页性能测试之WebPageTest

                                                                                            想知道您的网站,性能怎么样? 很自然,首先得找一个广被认可的测试工具.我们推荐WebPageTest: WebPageTest 它是google 开源项目”make the web faster “的 ...

                                                                                          3. layer弹出图片的问题

                                                                                            转载:https://blog.csdn.net/qq_41815146/article/details/81141088 layer下载地址:http://layer.layui.com/ jQue ...

                                                                                          4. cp和mv命令

                                                                                            注意事项:mv与cp的结果不同,mv好像文件“搬家”,文件个数并未增加.而cp对文件进行复制,文件个数增加了. 一.cp命令 cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录.它可以将 ...

                                                                                          5. 【OI】快读

                                                                                            不必多说. #include <cstdio> #include <cstring> int read(){ ,f = ; char c = getchar(); ') { ; ...

                                                                                          6. day39-Spring 01-上次课内容回顾

                                                                                          7. mysql锁机制之表锁(三)

                                                                                            顾名思义,表锁就是一锁锁一整张表,在表被锁定期间,其他事务不能对该表进行操作,必须等当前表的锁被释放后才能进行操作.表锁响应的是非索引字段,即全表扫描,全表扫描时锁定整张表,sql语句可以通过执行计划 ...

                                                                                          8. bzoj2752 高速公路

                                                                                              列式子: 如果把从i号收费站到i+1号收费站之间路段编号设为i. 假如查询l号收费站到r号收费站之间的期望值. $ Ans_{l,r} = \sum\limits_{i=l}^{r-1} v_i ...

                                                                                          9. json,pickle模块

                                                                                            序列化 把对象从内存中编成可储存或传输的过程称之为序列化,输出为json串,.json文件 反序列化 把json串反编成Python数据类型 json模块 用于跨平台交互 json模块下不可转换集合( ...

                                                                                          10. python 缓冲区 subprocess 黏包 黏包解决方案

                                                                                            一.缓冲区 二.两种黏包现象 两种黏包现象: 1 连续的小包可能会被优化算法给组合到一起进行发送 黏包现象1客户端 import socket BUFSIZE = 1024 ip_prort = (' ...