如果你的项目没有配置错误,配置文件名称也正常,还出现这个问题,那一定是你的yml文件编码的问题

先附上一张项目架构图

当我启动服务器寻找配置文件的时候,服务器提示这样的错误信息

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application-dev.yml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:549)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:488)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:468)
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:336)
at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:215)
at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:198)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:185)
at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:171)
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:74)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.dawn.rockcandy.RockCandyApplication.main(RockCandyApplication.java:11)
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:254)
at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:58)
at org.yaml.snakeyaml.Yaml.loadAll(Yaml.java:537)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:139)
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:567)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:523)
... 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:223)
... 31 common frames omitted

我的application.yml和application-dev.yml是没有配置错误的,而且我的文件名称是完全正常的,编译后的target文件里面也有application-dev.yml,我就很纳闷问题出在哪儿了!

打开target文件,查看application-dev.yml文件,发现这个文件居然是空的,说明这个文件编译失败了!!!

最后找到问题,因为这个文件的编码格式是GBK,项目的编码格式是UTF-8,里面有注释,注释乱码,导致编译失败

1.修改你的编码格式

2.删除注释

java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application-dev.yml'的更多相关文章

  1. java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

    java.lang.IllegalStateException: Failed to load property source from location 'classpath:/applicatio ...

  2. Springboot - java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'

    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple key in 'reader', lin ...

  3. Eureka启动报错:Failed to load property source from location 'classpath:/application.yml'

    原因: 将application.yml添加到classpath时, 由于变更了application.yml的编码格式(或许也改变了些代码内容), 而target内的yml文件没有实时更新, 从而导 ...

  4. springboot启动报异常,Failed to load property source from location 'classpath:/application.yml'

    学习springboot,在启动时抛出下图异常 往下看异常信息,找到异常的具体位置 找到application.yml文件的对应位置,发现params配置前面多了空格 去掉空格重新启动,可以了 写代码 ...

  5. Failed to load property source from location 'classpath:/applica)

    : 1.注释错误(application.yml用的是#注释) 2.缩进采用tab而不是空格引起的(不同配置之间也不能有tab出现,否则会报错) 3.冒号后面必须有空格否则会报错

  6. Spring3.x 版本和 JDK1.8 不兼容导致 java.lang.IllegalStateException: Failed to load ApplicationContext

    由于安装了 JDK1.8 的版本,最近在进行整合 Struts2+Spring+Hibernate 框架的时候,不小心导入了之前下载的 Spring 3.2.0 版本的 jar 包. 结果在运行测试用 ...

  7. java.lang.IllegalStateException: Failed to load ApplicationContext selenium 异常 解决

    WARN <init>, HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF R ...

  8. junit测试时,出现java.lang.IllegalStateException: Failed to load ApplicationContext

    课程设计要求进行junit测试,我是在已经做好的ssh项目上做的测试,测试类代码如下 package com.zhang.web.services; import static org.junit.A ...

  9. java.lang.IllegalStateException: Failed to load ApplicationContext

    1.错误描述 七月 13, 2014 6:34:41 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBean ...

随机推荐

  1. linux上用newman+postman进行自动化测试

    第一步:导出postman文件 Postman就是根据collection和enviroment这两个json文件来自动化运行的! 所以从Postman中导出collection和enviroment ...

  2. 安卓开发之自定义一个view弹出框

    https://www.cnblogs.com/muyuge/p/6152167.html

  3. BeanFactory和ApplicationContext的比较

    1.BeanFactory实例化后,不会马上实例化Bean:ApplicationContext在实例化后紧跟着就会实例化Bean 2.ApplicationContext还实现了ResourceLo ...

  4. c++面向对象学习计划

    面向对象自学计划 视频学习计划 计划:每天观看至少两个视频,到开学时差不多完成视频的学习. 进度:已学习12个视频. C的强化与补漏 C语言不熟悉的知识点:数组,结构体,链表,文件 -----已重新学 ...

  5. 使用openssl在windows 10下本地xampp配置https开发环境

    安装win64OpenSSL-1_1_0j后重新启动:以管理员权限启动powershell; 执行以下命令 set OPENSSL_CONF=c:\xampp\apache\conf\openssl. ...

  6. TERADATA数据库操作

    1.创建一个数据库的命令举例: ,spool; 注释:该命令创建了一个测试数据库testbase,其永久表空间为200mb,spool空间不能超过100mb.在teradata数据库系统的缺省方式下, ...

  7. 4.1Python数据处理篇之Matplotlib系列(一)---初识Matplotlib

    目录 目录 前言 (一)matplotlib的介绍 (二)画一个简单的画布 ==1.源代码== ==2.展示效果== (三)画布按键的功能介绍 ==1.对于画布功能键的排序== ==(1)主页== = ...

  8. Linux 小知识翻译 - 「RAID」

    最近术语「RAID」变得比较有名.「RAID」是指将多个HDD组合起来使用,从而提高存储可靠性的一种技术. 那么,关于 RAID 中的 「RAID 0」「RAID 1」「RAID 5」等各种「RAID ...

  9. Leviticus

    The head is empty and empty. Just practicing English will not have any effect. The best effect is to ...

  10. 学生与部门管理app-产品功能与界面的简单设计

    学生与部门管理app-产品功能与界面的简单设计 1. 结对成员学号 我:********* 大佬:*******10 2. 需求分析(NABCD模型) 2.1 N-需求 各个部门在开学初占据学校青春广 ...