行业资讯 2025年08月6日
0 收藏 0 点赞 368 浏览 1271 个字
摘要 :

有些同学在使用SpringBoot搭建项目时,启动Application提示如下错误: Failed to configure a DataSource: ‘url’ attribute is not specified and no embedd……

有些同学在使用SpringBoot搭建项目时,启动Application提示如下错误:

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
1、错误的意思大概是:未能确定合适的驱动程序类导致配置数据源失败

解决办法1:

可能的原因如下:
pom.xml中导入了类似如下mybatis依赖:

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.4</version>
</dependency>

但是在核心配置文件application.propertiesapplication.yml中没有配置数据库连接相关的属性,比如url、dirver、username、password等。
解决:
application.properties中新增数据库连接配置:

#数据库连接配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8&amp;serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456

或在application.yml中新增数据库连接配置:

#spring配置
spring:
  #数据库连接配置
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8&serverTimezone=UTC
    username: root
    password: 123456

解决办法2:

如果你添加了有关库的依赖但是又不想配置库的连接,可以使用Application启动类上@SpringBootApplication注解中配置如下即可:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

解决办法3:

如果第一种方式你尝试了但是还不能解决,还有一个可能的原因就是你的resources目录并没有设置为资源目录导致的,典型的特征就是Resources目录没有小黄标,如下:
SpringBoot启动报错Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured
我们需要打开File->Poroject Structure->Modules->Sources,展开目录找到resources目录将其置为Resources,如下:
SpringBoot启动报错Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured
然后apply->save,效果如下:
SpringBoot启动报错Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured

微信扫一扫

支付宝扫一扫

版权: 转载请注明出处:https://www.zuozi.net/7305.html

管理员

相关推荐
2025-08-06

文章目录 一、Reader 接口概述 1.1 什么是 Reader 接口? 1.2 Reader 与 InputStream 的区别 1.3 …

988
2025-08-06

文章目录 一、事件溯源 (一)核心概念 (二)Kafka与Golang的优势 (三)完整代码实现 二、命令…

465
2025-08-06

文章目录 一、证明GC期间执行native函数的线程仍在运行 二、native线程操作Java对象的影响及处理方…

348
2025-08-06

文章目录 一、事务基础概念 二、MyBatis事务管理机制 (一)JDBC原生事务管理(JdbcTransaction)…

456
2025-08-06

文章目录 一、SnowFlake算法核心原理 二、SnowFlake算法工作流程详解 三、SnowFlake算法的Java代码…

517
2025-08-06

文章目录 一、本地Jar包的加载操作 二、本地Class的加载方法 三、远程Jar包的加载方式 你知道Groo…

832
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力内容变现

将您的收入提升到一个新的水平

点击联系客服

在线时间:08:00-23:00

客服QQ

122325244

客服电话

400-888-8888

客服邮箱

122325244@qq.com

扫描二维码

关注微信客服号