詳解springboot中各個(gè)版本的redis配置問題
今天在springboot中使用數(shù)據(jù)庫,springboot版本為2.0.2.RELEASE,通過pom引入jar包,配置文件application.properties中的redis配置文件報(bào)錯(cuò),提示例如deprecated configuration property ’spring.redis.pool.max-active’,猜想應(yīng)該是版本不對,發(fā)現(xiàn)springboot在1.4前后集成redis發(fā)生了一些變化。下面截圖看下。
一、不同版本RedisProperties的區(qū)別這是springboot版本為1.3.2RELEASE中的RedisProperties配置文件類,從圖片中可以看得出來該本的redis配置文件屬性有兩個(gè)內(nèi)部靜態(tài)類分別是Pool和Sentinel,七個(gè)屬性變量。例如我們想在配置文件中設(shè)置redis數(shù)據(jù)庫host地址,則可以這樣寫
spring.redis.host=localhost host為屬性,配置連接池的最大連接數(shù) spring.redis.pool.max-active=8
這個(gè)是redis在application.properties中springboot低版本的配置
# REDIS (RedisProperties)# Redis數(shù)據(jù)庫索引(默認(rèn)為0)spring.redis.database=0# Redis服務(wù)器地址spring.redis.host=localhost# Redis服務(wù)器連接端口spring.redis.port=6379# Redis服務(wù)器連接密碼(默認(rèn)為空)spring.redis.password=# 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)spring.redis.pool.max-active=8# 連接池最大阻塞等待時(shí)間(使用負(fù)值表示沒有限制)spring.redis.pool.max-wait=-1# 連接池中的最大空閑連接spring.redis.pool.max-idle=8# 連接池中的最小空閑連接spring.redis.pool.min-idle=0# 連接超時(shí)時(shí)間(毫秒)spring.redis.timeout=0
下圖則是springboot版本為2.0.2RELEASE中的RedisProperties配置文件類,從圖中可知pool屬性則被封裝到了內(nèi)部靜態(tài)類Jedis和Lettuce中去了,這時(shí)我們要是配置連接池的最大連接數(shù),前綴還是spring.redis,有兩種途徑
spring.redis.jedis.pool.max-active=8 或者 spring.redis.lettuce.pool.max-active=8
這個(gè)是redis在application.properties中springboot高版本的配置
# REDIS (RedisProperties)# Redis數(shù)據(jù)庫索引(默認(rèn)為0)spring.redis.database=0# Redis服務(wù)器地址spring.redis.host=localhost# Redis服務(wù)器連接端口spring.redis.port=6379# Redis服務(wù)器連接密碼(默認(rèn)為空)spring.redis.password=# 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)spring.redis.jedis.pool.max-active=8# 連接池最大阻塞等待時(shí)間(使用負(fù)值表示沒有限制)spring.redis.jedis.pool.max-wait=-1# 連接池中的最大空閑連接spring.redis.jedis.pool.max-idle=8# 連接池中的最小空閑連接spring.redis.jedis.pool.min-idle=0# 連接超時(shí)時(shí)間(毫秒)spring.redis.timeout=0二、maven下pom中的坐標(biāo)配置
springboot版本1.4以下
<!--引入 spring-boot-starter-redis(1.4版本前)--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-redis</artifactId><version>1.3.2.RELEASE</version></dependency>
springboot版本1.4以上
<!--引入 spring-boot-starter-data-redis(1.4版本后)多了個(gè)data加個(gè)紅和粗吧--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency>
到此這篇關(guān)于詳解springboot中各個(gè)版本的redis配置問題的文章就介紹到這了,更多相關(guān)springboot各個(gè)版本redis配置內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. IntelliJ IDEA導(dǎo)入jar包的方法2. Python requests庫參數(shù)提交的注意事項(xiàng)總結(jié)3. SpringBoot參數(shù)校驗(yàn)與國際化使用教程4. vue-electron中修改表格內(nèi)容并修改樣式5. ajax請求添加自定義header參數(shù)代碼6. python操作mysql、excel、pdf的示例7. 詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法8. ASP基礎(chǔ)知識(shí)VBScript基本元素講解9. 使用Python和百度語音識(shí)別生成視頻字幕的實(shí)現(xiàn)10. JavaScript中l(wèi)ayim之整合右鍵菜單的示例代碼
