zoukankan      html  css  js  c++  java
  • 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发生了一些变化。下面截图看下。

    一、不同版本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)
    2. # Redis数据库索引(默认为0)
    3. spring.redis.database=0
    4. # Redis服务器地址
    5. spring.redis.host=localhost
    6. # Redis服务器连接端口
    7. spring.redis.port=6379
    8. # Redis服务器连接密码(默认为空)
    9. spring.redis.password=
    10. # 连接池最大连接数(使用负值表示没有限制)
    11. spring.redis.pool.max-active=8
    12. # 连接池最大阻塞等待时间(使用负值表示没有限制)
    13. spring.redis.pool.max-wait=-1
    14. # 连接池中的最大空闲连接
    15. spring.redis.pool.max-idle=8
    16. # 连接池中的最小空闲连接
    17. spring.redis.pool.min-idle=0
    18. # 连接超时时间(毫秒)
    19. 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高版本的配置

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

    2、maven下pom中的坐标配置

    springboot版本1.4以下

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

    springboot版本1.4以上

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

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-data-redis</artifactId>
    4. </dependency>
    原文地址:https://blog.csdn.net/qq_33326449/article/details/80457571
  • 相关阅读:
    register_shutdown_function
    字节转换
    考虑 PHP 5.0~5.6 各版本兼容性的 cURL 文件上传
    linux--svn checkout
    linux命令
    linux---mysql忘记密码
    array_merge函数的注意事项
    逻辑卷使用记录笔记
    系统设计时关于性能问题处理的几点心得
    SSH防暴力破解脚本
  • 原文地址:https://www.cnblogs.com/jpfss/p/11016445.html
Copyright © 2011-2022 走看看