当前位置:   article > 正文

Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping :yam文件报错解决

caused by: org.yaml.snakeyaml.parser.parserexception: while parsing a block
  1. person: "一号"
  2. age: 10
  3. name: "老王"

以上为yam文件片段,springboot运行时,会报以下错误:

  1. java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application-pro.yml'
  2. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:524)
  3. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:462)
  4. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:443)
  5. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:425)
  6. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$40/35534346.accept(Unknown Source)
  7. at java.lang.Iterable.forEach(Iterable.java:75)
  8. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:425)
  9. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader$$Lambda$39/2082781203.accept(Unknown Source)
  10. at java.lang.Iterable.forEach(Iterable.java:75)
  11. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:422)
  12. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:321)
  13. at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:202)
  14. at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:186)
  15. at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:176)
  16. at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:164)
  17. at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
  18. at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
  19. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
  20. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
  21. at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
  22. at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
  23. at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:340)
  24. at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
  25. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
  26. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
  27. at com.csii.ifinance.integration.IntegrationApplication.main(IntegrationApplication.java:17)
  28. Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping
  29. in 'reader', line 1, column 1:
  30. person: "一号"
  31. ^
  32. expected <block end>, but found '<block mapping start>'
  33. in 'reader', line 2, column 3:
  34. age: 10
  35. ^
  36. at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:572)
  37. at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
  38. at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
  39. at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:214)
  40. at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:144)
  41. at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:85)
  42. at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:123)
  43. at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:547)
  44. at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:160)
  45. at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:134)
  46. at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75)
  47. at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:49)
  48. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:542)
  49. at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:497)
  50. ... 25 common frames omitted
  51. Disconnected from the target VM, address: '127.0.0.1:63834', transport: 'socket'
  52. Process finished with exit code 1

原因分析:

yam文件有较为严格的格式,格式不正确就无法正常解析。由于本人也是第一次使用yam文件,不懂其规则。经百度才知道当该节点还有其他子节点时,该父节点不能有值。

解决方法,改成一下格式即可:

  1. person:
  2. age: 10
  3. name: "老王"

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/271384
推荐阅读
相关标签
  

闽ICP备14008679号