5fd9b351af6302580.png_fo742.png
报错:

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.load(ConfigFileApplicationListener.java:554)
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.loadForFileExtension(ConfigFileApplicationListener.java:500)
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.load(ConfigFileApplicationListener.java:467)
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.lambdanull6(ConfigFileApplicationListener.java:448)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.lambdaload7(ConfigFileApplicationListener.java:447)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.load(ConfigFileApplicationListener.java:444)
    at org.springframework.boot.context.config.ConfigFileApplicationListenerLoader.load(ConfigFileApplicationListener.java:332)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:207)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:190)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:177)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:163)
    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)
    at com.boot.druid.DruidApplication.main(DruidApplication.java:9)
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
    at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:218)
    at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:176)
    at org.yaml.snakeyaml.reader.StreamReader.ensureEnoughData(StreamReader.java:171)
    at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:126)
    at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1177)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:287)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:227)
    at org.yaml.snakeyaml.parser.ParserImplParseImplicitDocumentStart.produce(ParserImpl.java:195)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
    at org.yaml.snakeyaml.composer.Composer.checkNode(Composer.java:72)
    at org.yaml.snakeyaml.constructor.BaseConstructor.checkData(BaseConstructor.java:112)
    at org.yaml.snakeyaml.Yaml1.hasNext(Yaml.java:542)
    at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:161)
    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.ConfigFileApplicationListenerLoader.loadDocuments(ConfigFileApplicationListener.java:572)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:526)
    ... 23 common frames omitted
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at org.yaml.snakeyaml.reader.UnicodeReader.read(UnicodeReader.java:125)
    at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:183)
    ... 41 common frames omitted

Process finished with exit code 1

原因是: 在编写yml文件时, 这个文件可能是使用了GBK的编码方式, 在读取这个文件时, 如果文件有中文注释解, 它会认为读到的字节为半个字节, 要求要为1,所以才会报一下这个错误

要么修改编码方式, 要么去掉注解.

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code