詳解springboot中各個(gè)版本的redis配置問題
今天在springboot中使用數(shù)據(jù)庫(kù),springboot版本為2.0.2.RELEASE,通過pom引入jar包,配置文件application.properties中的redis配置文件報(bào)錯(cuò),提示例如deprecated configuration property ’spring.redis.pool.max-active’,猜想應(yīng)該是版本不對(duì),發(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ù)庫(kù)host地址,則可以這樣寫
spring.redis.host=localhost host為屬性,配置連接池的最大連接數(shù) spring.redis.pool.max-active=8
這個(gè)是redis在application.properties中springboot低版本的配置
# REDIS (RedisProperties)# Redis數(shù)據(jù)庫(kù)索引(默認(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ù)庫(kù)索引(默認(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)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法2. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲3. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明4. ASP.NET MVC遍歷驗(yàn)證ModelState的錯(cuò)誤信息5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向7. asp中response.write("中文")或者js中文亂碼問題8. PHP設(shè)計(jì)模式中工廠模式深入詳解9. CSS hack用法案例詳解10. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法
