首页 > 软件编程 > java > SpringBoot Failed to load property source from location 'classpath:/application.yml'
解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'问题
作者:一只未入门的程序猿
这篇文章主要介绍了解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
在启动SpringBoot项目时报如下错误
原因可能是
1.yml中语法错误
(特别注意:在yml中key与value之间是有一个空格的),仔细检查一下语法
server: port: 8090 #在这里,key值与value之间有有一个空格 spring: application: name: demo datasource: username: root password: root driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3308/test?characterEncoding=utf8&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai hikari: read-only: false connection-timeout: 60000 idle-timeout: 60000 validation-timeout: 3000 max-lifetime: 60000 login-timeout: 5 maximum-pool-size: 60 minimum-idle: 10 mvc: view: prefix: classpath:/templates/ suffix: .html devtools: restart: enabled: true mail: default-encoding: utf-8 host: smtp.qq.com protocol: smtp username: password: properties: mail: smtp: auth: true starttls: enable: true required: true mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.example.demo.vo logging: level: com.example.demo.mapper: debug
2.yml文件格式是GBK
但是在yml中写了中文注释,如下图:
- a. 最直接的解决方法就是删除yml中的所有中文注释(简单粗暴直接);
- b. 修改yml文件的编码格式为utf-8
在File->Settings->Editor->File Encodings 里面设置编码格式为utf-8
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。