詳解springboot中各個版本的redis配置問題
今天在springboot中使用數(shù)據(jù)庫,springboot版本為2.0.2.RELEASE,通過pom引入jar包,配置文件application.properties中的redis配置文件報錯,提示例如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配置文件屬性有兩個內(nèi)部靜態(tài)類分別是Pool和Sentinel,七個屬性變量。例如我們想在配置文件中設(shè)置redis數(shù)據(jù)庫host地址,則可以這樣寫
spring.redis.host=localhost host為屬性,配置連接池的最大連接數(shù) spring.redis.pool.max-active=8

這個是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 # 連接池最大阻塞等待時間(使用負(fù)值表示沒有限制) spring.redis.pool.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屬性則被封裝到了內(nèi)部靜態(tài)類Jedis和Lettuce中去了,這時我們要是配置連接池的最大連接數(shù),前綴還是spring.redis,有兩種途徑
spring.redis.jedis.pool.max-active=8 或者 spring.redis.lettuce.pool.max-active=8

這個是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 # 連接池最大阻塞等待時間(使用負(fù)值表示沒有限制) 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中的坐標(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版本后)多了個data加個紅和粗吧--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
到此這篇關(guān)于詳解springboot中各個版本的redis配置問題的文章就介紹到這了,更多相關(guān)springboot各個版本redis配置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java數(shù)據(jù)結(jié)構(gòu)之選擇排序算法的實現(xiàn)與優(yōu)化
選擇排序:(Selection?sort)是一種簡單直觀的排序算法,也是一種不穩(wěn)定的排序方法。本文主要為大家介紹一下選擇排序的實現(xiàn)與優(yōu)化,希望對大家有所幫助2023-01-01
java微信小程序步數(shù)encryptedData和開放數(shù)據(jù)解密的實現(xiàn)
這篇文章主要介紹了java微信小程序步數(shù)encryptedData和開放數(shù)據(jù)解密的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
JSON.parseObject和JSON.toJSONString實例詳解
這篇文章主要為大家詳細(xì)介紹了JSON.parseObject和JSON.toJSONString實例,具有一定的參考價值,感興趣的朋友可以參考一下2018-06-06
Java使用POI從Excel讀取數(shù)據(jù)并存入數(shù)據(jù)庫(解決讀取到空行問題)
有時候需要在java中讀取excel文件的內(nèi)容,專業(yè)的方式是使用java POI對excel進(jìn)行讀取,這篇文章主要給大家介紹了關(guān)于Java使用POI從Excel讀取數(shù)據(jù)并存入數(shù)據(jù)庫,文中介紹的辦法可以解決讀取到空行問題,需要的朋友可以參考下2023-12-12
修改request的parameter的幾種方式總結(jié)
這篇文章主要介紹了修改request的parameter的幾種方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08
Flowable?設(shè)置任務(wù)處理人的四種方式詳解
這篇文章主要為大家介紹了Flowable?設(shè)置任務(wù)處理人的四種方式詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10

