SpringBoot启动yaml报错
报错找不到org.yaml里的一个方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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.第一个坑
原代码:
1
2
|
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