SpringBoot启动yaml报错的解决
作者:草宝虫 时间:2021-09-09 22:58:14
SpringBoot启动yaml报错
报错找不到org.yaml里的一个方法
10:45:54.742 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.yaml.snakeyaml.nodes.ScalarNode.getScalarStyle()Lorg/yaml/snakeyaml/DumperOptions$ScalarStyle;
at org.springframework.boot.env.OriginTrackedYamlLoader$KeyScalarNode.<init>(OriginTrackedYamlLoader.java:127)
at org.springframework.boot.env.OriginTrackedYamlLoader$KeyScalarNode.get(OriginTrackedYamlLoader.java:138)
at org.springframework.boot.env.OriginTrackedYamlLoader$KeyScalarNode.get(OriginTrackedYamlLoader.java:133)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
at org.springframework.boot.env.OriginTrackedYamlLoader$OriginTrackingConstructor.replaceMappingNodeKeys(OriginTrackedYamlLoader.java:99)
at org.springframework.boot.env.OriginTrackedYamlLoader$OriginTrackingConstructor.constructObject(OriginTrackedYamlLoader.java:92)
at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:161)
at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:127)
at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:547)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:160)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:134)
at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75)
at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:574)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:528)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:502)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:469)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:450)
at java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:449)
at java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:446)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:334)
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:209)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:192)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:179)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
解决
核对了下引入的包,发现项目中额外引入了1.19版本的org.yaml.snakeyaml包,这个包里确实没有这个方法。把这个包改成1.26的即可。
SpringBoot配置文件application.yml遇到的坑
1.第一个坑
原代码:
username:root
password:123456
项目启动报以下异常:
Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key
产生问题的根源:application.yml文件键、值对之间要用冒号:隔开,而且冒号和值之间有一个空格
上述异常产生的就是键后面的:号紧接着写值,没有留一个空格。
解决办法:
冒号:后面留出一个空格后再写值
2.第二个坑
原代码参见下图:
项目启动以后报以下异常:
Caused by: org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here
或
Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing a block mapping
expected <block end>, but found '<block mapping start>'
in 'reader', line 11, column 3:
jpa:
产生问题的根源:application.yml一级键,空一格写就可以了。像Jpa这样是一级键,下属的database是二级键。
解决办法:
Jpa向左前进一格到中间箭头的方位即可。
来源:https://wanghq.blog.csdn.net/article/details/109486222
标签:SpringBoot,yaml,报错
0
投稿
猜你喜欢
Spring IOC:CreateBean环节中的流程转换
2022-06-10 12:28:31
C#双向链表LinkedList排序实现方法
2021-08-19 14:06:16
Java并发线程池实例分析讲解
2022-08-05 20:25:40
C# wpf Grid中实现控件拖动调整大小的示例代码
2023-05-15 17:12:03
C#二进制读写BinaryReader、BinaryWriter、BinaryFormatter
2022-03-07 23:01:28
C#3.0中Lambda表达式详解
2023-08-08 04:01:37
Scala中的mkString的具体使用方法
2023-11-16 00:18:18
深入理解Android热修复技术原理之资源热修复技术
2021-08-12 06:13:57
springmvc前台向后台传值几种方式总结(从简单到复杂)
2023-04-13 22:20:50
Android Fragment概述及用法
2022-08-23 15:54:22
SpringCloud之Config配置中心与Redis分布式锁详解
2023-12-21 02:14:41
Android中的深度链接技术实战
2023-09-20 11:27:18
JAVA文件扫描(递归)的实例代码
2022-04-08 08:37:20
详解SpringBoot项目整合Vue做一个完整的用户注册功能
2022-02-13 21:46:35
C# 执行CMD命令并接收返回结果的操作方式
2023-09-03 10:36:56
Android自定义View实现渐变色进度条
2022-11-25 08:27:17
mybatis的插件机制示例详解
2023-02-24 23:46:17
Android自定义ActionProvider ToolBar实现Menu小红点
2022-09-09 05:07:30
Java中JSON处理工具类使用详解
2023-09-19 17:59:08
C语言结构体版学生成绩管理系统
2021-11-05 03:29:41