SpringCloud启动失败问题汇总
作者:困知勉行1985
SpringCloud启动失败问题
Nacos配置读取失败
org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:218) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:176) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:171) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:126) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1177) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.constructor.BaseConstructor.checkData(BaseConstructor.java:123) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.Yaml$1.hasNext(Yaml.java:507) ~[snakeyaml-1.27.jar!/:na]
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:198) ~[spring-beans-5.3.8.jar!/:5.3.8]
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166) ~[spring-beans-5.3.8.jar!/:5.3.8]
at com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadNacosPropertySource(NacosPropertySourceLocator.java:199) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar!/:2021.1]
com.alibaba.cloud.nacos.client.NacosPropertySourceLocator.loadExtConfiguration(NacosPropertySourceLocator.java:128) [spring-cloud-starter-alibaba-nacos-config-2021.1.jar!/:2021.1]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [app.jar:1.0.0]
Caused by: java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(Unknown Source) ~[na:1.8.0_311]
at sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[na:1.8.0_311]
at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[na:1.8.0_311]
at java.io.InputStreamReader.read(Unknown Source) ~[na:1.8.0_311]
at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:125) ~[snakeyaml-1.27.jar!/:na]
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:183) ~[snakeyaml-1.27.jar!/:na]
... 41 common frames omitted
2022-02-24 15:50:08.897 ERROR 39048 --- [ main] c.a.c.n.c.NacosPropertySourceBuilder : parse data from Nacos error,dataId:dbsource.yml,data:spring:
main:
allow-bean-definition-overriding: true
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
login-username: admin
login-password: admin
reset-enable: false
Root cause:
编码不一致,nacos读取配置文件时默认编码为utf-8,而通过cmd启动项目默认使用gbk。
解决方案
添加-Dfile.encoding=utf-8 启动参数
java -Dfile.encoding=utf-8 -jar app.jar
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。