spring boot 使用application.yml作为配置文件格式也特别注意

在进行spring boot 开发时,我们现在都比较喜欢使用application.yml来作为配置文件,而不喜欢使用application.properties来配置。

我个人认为还是使用application.yml比较直观,易读一些, 但是书写格式一定要注意:
(1)yml文件采用空格的形式,都是偶数个空格,主关键字顶头,次之关键字换行2个空格,依次类推。。。

刚开发的时候不太注意,所以走了不少弯路,血泪史啊。

记得刚开始配置支持jsp的时候,

当时我的yml文件配置jsp的路径如下:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/sboottest?characterEncoding=utf-8
    username: root
    password: ailong
    #使用druid数据源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    #可以使用监控过滤器,配置监控统计的filters,去掉后监控界面sql将无法统计,‘wall’用于防火墙
    filters: stat,wall.log4j
    #最大活跃数
    maxActive: 20
    #初始化数量
    initialSize: 1
    maxWait: 60000
    #通过connectionProperties属性来打开mergeSql功能;慢查询记录
    #connectionProperties:druid.stat.mergeSql=true
    #druid.stat.slowSqlMillis=5000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    #打开pscache
    poolPreparedStatements: true
    maxOpenPreparedStatements: 20
  mvc:
    view:
    prefix: /WEB-INF/jsp/
    suffix: .jsp

看上面的配置,我调试了半天都是报错,因为项目中加入了拦截器,权限管理spring security,总以为是哪里出问题了,找了半天,调试了半天,还是不行,因为yml配置文件也不报错。 

最后无意间发现,配置文件怎么被改动过(我之前是可以访问jsp文件,所以就没太在意是yml文件配置错误),可能是什么时候不小心改动了吧,上面代码修改为

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/sboottest?characterEncoding=utf-8
    username: root
    password: ailong
    #使用druid数据源
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    #可以使用监控过滤器,配置监控统计的filters,去掉后监控界面sql将无法统计,‘wall’用于防火墙
    filters: stat,wall.log4j
    #最大活跃数
    maxActive: 20
    #初始化数量
    initialSize: 1
    maxWait: 60000
    #通过connectionProperties属性来打开mergeSql功能;慢查询记录
    #connectionProperties:druid.stat.mergeSql=true
    #druid.stat.slowSqlMillis=5000
    minIdle: 1
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: select 'x'
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    #打开pscache
    poolPreparedStatements: true
    maxOpenPreparedStatements: 20
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp

在prefix和suffix前各自加了二个空格,重启sb后,就ok了。细节一定要注意!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值