项目总结35:SpringBoot中application.yml配置报mapping values are not allowed here in 'reader'异常(和配置顺序有关)

项目总结35:SpringBoot中application.yml配置报mapping values are not allowed here  in 'reader'异常(和配置顺序有关)

异常日志

11:16:22.860 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here
 in 'reader', line 75, column 16:
      configuration:
                   ^

    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:871)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:360)
    ……………………………………………………

出错的application.yml片段

mybatis:
  typeAliasesPackage: com.hzsun.shr.web.maintenance.entity
 mapper-locations: classpath:com/hzsun/shr/web/maintenance/mapper/**/*.xml
  configuration: #这是第75行
    map-underscore-to-camel-case: true

原因分析

  1-没有按照规定格式写配置,比如冒号:后面需要加空格;检查没问题后,再次启动报同样的异常

  2-其他原因

最后分析发现错误原因是:该处的mybatis配置顺序不对,正确的顺序如下

mybatis:
  typeAliasesPackage: com.hzsun.shr.web.maintenance.entity
  configuration:
    map-underscore-to-camel-case: true
 mapper-locations: classpath:com/hzsun/shr/web/maintenance/mapper/**/*.xml

 分析错误的原因:application.yml加载配置是有顺序要求,比如加载

mapper-locations: classpath:com/hzsun/shr/web/maintenance/mapper/**/*.xml

之前,必须先加载(因为类的映射和驼峰法则都在*/xml中有体现)

  typeAliasesPackage: com.hzsun.shr.web.maintenance.entity
  configuration:
    map-underscore-to-camel-case: true

猜你喜欢

转载自www.cnblogs.com/wobuchifanqie/p/11602222.html