启动Spring服务报错“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could not found”。
检查application.yml文件,确认已配置spring.datasource

spring:
  application:
    name: ignite-server-7001

      #数据源的配置
    datasource:
      type: com.alibaba.druid.pool.DruidDataSource
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/ignite?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
      password: 123456
      username: root

    #mybatis的配置
  mybatis:
    type-aliases-package: ignite.server
    mapper-locations: classpath:mapper/*.xml
    configuration:
      map-underscore-to-camel-case: on

发现问题没?这里考验大家对yaml文件配置格式的理解程度了。
上面datasource配置缩进不对,yaml对配置的缩进非常敏感,datasouce多缩进,导致springboot无法正确识别datasource的配置项。
正确的配置缩进如下:
datasource和application 、mybatis是对齐的,同一配置级别的。

spring:
  application:
    name: ignite-server-7001

      #数据源的配置
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ignite?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    password: 123456
    username: root

    #mybatis的配置
  mybatis:
    type-aliases-package: ignite.server
    mapper-locations: classpath:mapper/*.xml
    configuration:
      map-underscore-to-camel-case: on

今日踩坑,mark一下,也供参考~

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐