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
  • 相关阅读:
    美国首位女计算机博士荣获今年图灵奖
    此人需要关注一下
    Microsoft的壮大与IBM对Sun的收购
    文章介绍:Sexy Lexing with Python
    程序员的门道
    闲谈:敏捷与否的区分方法、对组织内部人员的现实作用与长远利益
    聊聊最俗的工厂相关话题
    人之患在好为人师
    TIOBE的头头儿和“反Java”的教授
    敏捷的核心究竟是什么
  • 原文地址:https://www.cnblogs.com/wobuchifanqie/p/11602222.html
Copyright © 2011-2022 走看看