zoukankan      html  css  js  c++  java
  • 项目总结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
  • 相关阅读:
    JVM,反射与动态代理
    11款实用的一句话网站设计代码
    Winform TextBox中只能输入数字的几种常用方法(C#)
    列表checkbox全选
    函数调用约定
    vs编译后在本机能运行,在别的机器上运行提示runtime Error的问题
    学习地形编程(一)
    Ogre中动态三维鼠标的实现
    讲讲volatile的作用
    绕任意轴旋转的推导
  • 原文地址:https://www.cnblogs.com/wobuchifanqie/p/11602222.html
Copyright © 2011-2022 走看看