Failed to load property source from location 'classpath:/application.yml'
来源:互联网 发布:天眼查官网软件下载 编辑:程序博客网 时间:2024/05/22 13:08
今天尝试着从 yml 文件读取数据加载到 JavaBean对象中报错:
14:12:20.559 [main] ERROR org.springframework.boot.SpringApplication - Application startup failedjava.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:476)at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:386)at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:225)at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:195)at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182)at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:168)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:122)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:325)at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)at testSpringBoot.Application.main(Application.java:14)Caused by: org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here in 'reader', line 2, column 9: servers: ^at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:871)at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:360)at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:557)at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:157)at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:147)at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:224)at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122)at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:84)at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:104)at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:471)at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:160)at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:138)at org.springframework.boot.env.YamlPropertySourceLoader$Processor.process(YamlPropertySourceLoader.java:101)at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:58)at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:127)at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.doLoadIntoGroup(ConfigFileApplicationListener.java:490)at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadIntoGroup(ConfigFileApplicationListener.java:473)... 17 common frames omitted
最终原因居然是: yml文件的注释是 # 而不是 //
错误写法:
my: // 注释 servers: - dev.bar.com - foo.bar.com - jiaobuchong.com正确写法:
my: # 注释 servers: - dev.bar.com - foo.bar.com - jiaobuchong.com
总结: 大意了,类似错误要检查该文件的内容格式是否错误。
阅读全文
0 0
- Failed to load property source from location 'classpath:/application.yml'
- Spring boot bootstrap.yml文件使用遇见的坑Failed to load property source from location 'classpath:/bootstrap.
- elasticsearch配置文件里的一些坑 [Failed to load settings from [elasticsearch.yml]]
- elasticsearch按照配置时遇到的一些坑 [Failed to load settings from [elasticsearch.yml]]
- spring:<context:property-placeholder location="classpath:application.properties" />
- spring:<context:property-placeholder location="classpath:application.properties" />
- spring:<context:property-placeholder location="classpath:application.properties" />
- 使用cxf创建webservice发生“Failed to import bean definitions from URL location [classpath:META-INF/cxf/cxf”
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- Spring配置文件元素<context:property-placeholder location="classpath:application.properties" />
- Dispatcher initialization failed Unable to load configuration. - [unknown location]
- Configuration problem: Failed to import bean definitions from relative location
- Could not copy property 'id' from source to target异常
- Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement'
- Failed to load Main-Class manifest attribute from logTjOutputUtil.jar
- Failed to load Main-Class manifest attribute from
- Failed to load Main-Class manifest attribute from
- Failed to load Main-Class manifest attribute from ....
- 编写函数,将三个int型整数按升序排列
- 学习Hadoop第二课(JDK的安装)
- c#文件读取和写入
- 老手心得:不熟悉的品种不做,看不懂的走势不做
- 英文版ubuntu16.04安装、添加中文输入法
- Failed to load property source from location 'classpath:/application.yml'
- DistinctSubsequences
- http协议
- 【网络管理者必知】2分钟带你了解新出台的《网络安全法》!
- Docker部署(一):服务器架构
- 初识View-FOUR
- eclipse+tomcat热部署Web项目
- svm算法 最通俗易懂讲解
- Brew error: Could not symlink 问题解决