Failed to configure a DataSource

简介: Failed to configure a DataSource

1 问题

近日在学习一个SpringBoot项目时,运行该项目时系统抛出

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class。

2 方法

  1. 找出问题:
    1.1根据提示,翻译问题。
    配置数据源失败:未指定“url”属性,无法配置嵌入式数据源。
    原因:无法确定合适的驱动程序类别。
    即:在应用中没有配置datasource的一些相关属性
  2. 解决方法:

2.1方法一:

找到application.properties,设置驱动程序及相关属性。

2.2方法二:

把spring boot自动初始化DataSource相关的代码禁止掉

在启动类头部声明:

@SpringBootApplication(exclude= DataSourceAutoConfiguration.class)

Exclude:排除此类的AutoConfig,即禁止 SpringBoot 自动注入数据源配置。

3 结语

程序启动可能会面临着各种各样的错误,在该项目学习时,面对依赖的问题,让小编花了很多时间去解决,后续会进行依赖相关的问题进行讲解。在使用时,推荐使用第二种方法,较为简单实用。

目录
相关文章
|
Java Spring 容器
如何解决spring EL注解@Value获取值为null的问题
本文探讨了在使用Spring框架时,如何避免`@Value("${xxx.xxx}")`注解导致值为null的问题。通过具体示例分析了几种常见错误场景,包括类未交给Spring管理、字段被`static`或`final`修饰以及通过`new`而非依赖注入创建对象等,提出了相应的解决方案,并强调了理解框架原理的重要性。
1219 5
|
druid Java 数据库连接
Spring Boot3整合MyBatis Plus
Spring Boot3整合MyBatis Plus
2227 1
|
SpringCloudAlibaba 安全 Java
SpringCloud版本升级后bootstrap.yml配置不生效
SpringCloud版本升级后bootstrap.yml配置不生效
3021 1
|
Java 数据库连接 Spring
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could
这个错误通常出现在使用Spring Boot进行数据库连接时。错误信息表明Spring Boot未能配置一个DataSource,因为没有指定'url'属性,并且没有发现默认的数据库连接。
6293 0
|
前端开发 Java 数据库连接
35个项目,开源,开源!
35个项目,开源,开源!
1846 0
35个项目,开源,开源!
|
Java 数据库 Spring
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
501 0
|
关系型数据库 MySQL Java
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
解决方法: 配置H2数据库或者MySQL数据库,其中配置MySQL解决方法如下: 1、添加 MySQL连接驱动的依赖 Maven工程在pom.xml中添加
3439 0
|
Java 关系型数据库 MySQL
【已解决】SpringBoot 启动报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no emb
【已解决】SpringBoot 启动报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no emb
10082 1
|
JSON Java 测试技术
SpringBoot实用开发篇第二章(测试操作)
SpringBoot实用开发篇第二章(测试操作)