【SpringBoot项目启动问题】Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded

SpringBoot项目启动问题(Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.)

SpringBoot项目启动报错:Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

异常现象

我在Spring Boot中关联MySQL、Mybatis进行数据库开发时,按照正常步骤添加了相关数据库的依赖,也进行了必要的数据库配置,结果在项目启动时出现如下异常信息:

在这里插入图片描述

看提示信息是说当前项目没有配置DataSource相关的配置!

解决方法

1、在application.yml/application.properties中添加数据库相关配置;

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf8
&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
&nullCatalogMeansCurrent=true
    username: root
    password: root

注意:在添加数据库配置文件时,要注意url的时区配置,有可能是因为没有配置时区导致报错;

设置时区时,添加serverTimezone参数,比如serverTimezone=GMT%2B8(URL 中 %2B表示+号,GMT%2B8即为GMT+8)。

  • GMT+8 表示东八区,北京时间
  • Asia/Shanghai 表示上海时间,也是东八区

2、在@SpringBootApplication注解中进行数据库配置的排除,即@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})。这也是最简单的解决办法。

在这里插入图片描述

修改之后我们来运行一下:

在这里插入图片描述

那么我们可以看到,项目也是成功启动了!不知道这篇文章对你有没有帮助呢,喜欢的话给作者点个赞吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

科研达人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值