項目總結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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM