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
  1. yml文件格式是GBK,但是在yml中写了中文注释,如下图:
    在这里插入图片描述
    a. 最直接的解决方法就是删除yml中的所有中文注释(简单粗暴直接);
    b. 修改yml文件的编码格式为utf-8
    在File->Settings->Editor->File Encodings 里面设置编码格式为utf-8

    在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值