解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'
目录
- 在启动SpringBoot项目时报如下错误
- 原因可能是
- 1.yml中语法错误
- 2.yml文件格式是GBK
- 总结
在启动SpringBoot项目时报如下错误
原android因可能是
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 conphpnection-tijsmeout: 60000 idle-timeout: 60000 validation-timeout: 3000 max-lifetime: 60000 login-timeout: 5 maximum-pool-size: 60 minimum-idle: 10 mvc: http://www.devze.comview: prefix: classpath:/templates/ suffix: .html dephpvtools: 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
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
精彩评论