详解springboot中各个版本的redis配置问题

网友投稿 306 2023-01-18

详解springboot中各个版本的redis配置问题

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

一、不同版本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低版本的配置

# REDIS (RedisProperties)

# Redis数据库索引(默认为0)

spring.redis.database=0

# Redis服务器地址

spring.redis.host=localhost

# Redis服务器连接端口

spring.redis.port=6379

# Redis服务器连接密码(默认为空)

spring.redis.password=

# 连接池最大连接数(使用负值表示没有限制)

spring.redis.pool.max-active=8

# 连接池最大阻塞等待时间(使用负值表示没有限制)

spring.redis.jCwglpool.max-wait=-1

# 连接池中的最大空闲连接

spring.redis.pool.max-idle=8

# 连接池中的最小空闲连接

spring.redis.pool.min-idle=0

# 连接超时时间(毫秒)

spring.redis.timeout=0

下图则是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高版本的配置

# REDIS (RedisProperties)

# Redis数据库索引(默认为0)

spring.redis.database=0

# Redis服务器地址

spring.redis.host=localhost

# Redis服务器连接端口

spring.redis.port=6379

# Redis服务器连接密码(默认为空)

spring.redis.password=

# 连接池最大连接数(使用负值表示没有限制)

spring.redis.jedis.pool.max-active=8

# 连接池最大阻塞等待时间(使用负值表示没有限制)

spring.redis.jedis.pool.max-wait=-1

# 连接池中的最大空闲连接

spring.redis.jedis.pool.max-idle=8

# 连接池中的最小空闲连接

spring.redis.jedis.pool.min-idle=0

# 连接超时时间(毫秒)

spring.redis.timeout=0

二、maven下pom中的坐标配置

springboot版本1.4以下

org.springframewojCwglrk.boot

spring-boot-starter-redis

1.3.2.RELEASE

springboot版本1.4以上

org.springframework.boot

spring-boot-starter-data-redis

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:营销短信接口api(平台短信接口)
下一篇:图片免费鉴黄api(图片鉴黄功能)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~