yml中某些配置不生效的解决方案

起因

将springboot项目的properties配置文件改为yml之后redis死活连不上了。

找问题

springboot的配置文件有两种方式:properties和yml,之前properties时候是没有任何问题的,那么来看一下yml的配置:

spring:
# Redis数据库索引(默认为0)
  redis:
    #数据库索引
    database: 0
    host: 127.0.0.1
    port: 6379
    password: 123456789
    jedis:
      pool:
        #最大连接数
        max-active: 8
        #最大阻塞等待时间(负数表示没限制)
        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的严格的模板校验
    mode: LEGACYHTML5
    prefix: classpath:/templates/
    suffix: .html
    excluded-view-names:
spring:
  groovy:
    template:
      cache: false

看起来貌似也没什么问题,bug,debug跟源码代码发现redis配置均未起作用,但是有个神奇的地方,如果把下面的thymeleaf和groovy都删掉,redis配置就起作用了,推测肯定是某个地方冲突了,仔细瞅,上面配置文件中有三个“spring:”,删掉下面两个“spring:”,果然一切ok。

解决

保证不能有重复的一级节点。
也许只是简单的知识点,但是只有踩过,才知道坑深,此坑爬了三个小时,希望小伙伴们不要再爬此坑······
正确配置如下

# THYMELEAF (ThymeleafAutoConfiguration)
spring:
  thymeleaf:
    cache: false
    check-template: true
    check-template-location: true
    enabled: true
    encoding: utf-8
    #去掉thymeleaf的严格的模板校验
    mode: LEGACYHTML5
    prefix: classpath:/templates/
    suffix: .html
    excluded-view-names:
  groovy:
    template:
      cache: false
# Redis数据库索引(默认为0)
  redis:
    #数据库索引
    database: 0
    host: 127.0.0.1
    port: 6379
    password: 123456789
    jedis:
      pool:
        #最大连接数
        max-active: 8
        #最大阻塞等待时间(负数表示没限制)
        max-wait: -1ms
        #最大空闲
        max-idle: 8
        #最小空闲
        min-idle: 0
    timeout: 300s
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值