【SpringBoot】‘url‘ attribute is not specified and no embedded datasource could be configured.

时间:2025-04-20 20:57:09

文章目录

  • 一、报错内容
  • 二、解决方法

一、报错内容

Description:

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

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

这段代码导致的:

<!--  mysql connector-->
<dependency>
   <groupId></groupId>
    <artifactId>mysql-connector-j</artifactId>
   <!--配置的运行时,则一定要在配置文件中配置数据库连接信息,否则报错-->
  <scope>runtime</scope>
</dependency>

二、解决方法

中配置的 jar 包作用范围是 scope,即运行时,则一定要在配置文件中配置数据库连接信息,否则报错。

更正如下:

spring:
  # 数据库连接信息
  datasource:
    type: 
    url: jdbc:mysql://localhost:3306/books-manage-system?useSSL=false&characterEncoding=UTF-8&serverTimezone=UTC
    driver-class-name: 
    username: xxx
    password: xxx