起因
將springboot項(xiàng)目的properties配置文件改為yml之后redis死活連不上了胶台。
找問題
springboot的配置文件有兩種方式:properties和yml鸡捐,之前properties時(shí)候是沒有任何問題的,那么來看一下yml的配置:
spring:
# Redis數(shù)據(jù)庫索引(默認(rèn)為0)
redis:
#數(shù)據(jù)庫索引
database: 0
host: 127.0.0.1
port: 6379
password: 123456789
jedis:
pool:
#最大連接數(shù)
max-active: 8
#最大阻塞等待時(shí)間(負(fù)數(shù)表示沒限制)
max-wait: -1ms
#最大空閑
max-idle: 8
#最小空閑
min-idle: 0
timeout: 300s
# THYMELEAF (ThymeleafAutoConfiguration)
spring:
thymeleaf:
cache: false
check-template: true
check-template-location: true
enabled: true
encoding: utf-8
#去掉thymeleaf的嚴(yán)格的模板校驗(yàn)
mode: LEGACYHTML5
prefix: classpath:/templates/
suffix: .html
excluded-view-names:
spring:
groovy:
template:
cache: false
看起來貌似也沒什么問題,bug庶艾,debug跟源碼代碼發(fā)現(xiàn)redis配置均未起作用魔种,但是有個(gè)神奇的地方掸屡,如果把下面的thymeleaf和groovy都刪掉封寞,redis配置就起作用了,推測肯定是某個(gè)地方?jīng)_突了仅财,仔細(xì)瞅狈究,上面配置文件中有三個(gè)“spring:”,刪掉下面兩個(gè)“spring:”盏求,果然一切ok抖锥。
解決
保證不能有重復(fù)的一級(jí)節(jié)點(diǎn)。
也許只是簡單的知識(shí)點(diǎn)碎罚,但是只有踩過磅废,才知道坑深,此坑爬了三個(gè)小時(shí)荆烈,希望小伙伴們不要再爬此坑······
正確配置如下
# THYMELEAF (ThymeleafAutoConfiguration)
spring:
thymeleaf:
cache: false
check-template: true
check-template-location: true
enabled: true
encoding: utf-8
#去掉thymeleaf的嚴(yán)格的模板校驗(yàn)
mode: LEGACYHTML5
prefix: classpath:/templates/
suffix: .html
excluded-view-names:
groovy:
template:
cache: false
# Redis數(shù)據(jù)庫索引(默認(rèn)為0)
redis:
#數(shù)據(jù)庫索引
database: 0
host: 127.0.0.1
port: 6379
password: 123456789
jedis:
pool:
#最大連接數(shù)
max-active: 8
#最大阻塞等待時(shí)間(負(fù)數(shù)表示沒限制)
max-wait: -1ms
#最大空閑
max-idle: 8
#最小空閑
min-idle: 0
timeout: 300s