【BUG集绵】Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

【BUG】Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

报错截图:
在这里插入图片描述

报错内容:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-08-10 18:31:09.742 ERROR 2220 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

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).

报错原因分析:数据库配置异常。

报错溯源,一般可以从如下几点着手:

(1)首先检查项目的application.yml或application.properties中是否有添加数据库相关配置。比如:

spring:
  datasource:
    druid:
      driver-class-name: com.mysql.cj.jdbc.Driver
      url: jdbc:mysql://localhost:3306/xcplus_content?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
      username: root
      password: root

(2)如果项目是多模块开发,同级模块都有application.yml 或 application.properties同名文件的话,
可以尝试修改为不同的规范文件名,比如:application-dev.yml
(3)在SpringBootApplication注解中进行数据库配置的排除,即@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})。
(4)项目是多模块开发且不同模块中的配置文件,以application-*.yml的形式命名,比如application-mapper.yml,application-service.yml等,然后在最顶层的shop-web模块配置文件中,通过spring.profiles.active进行激活配置

spring:
  profiles:
  	# 加载不同模块的配置文件
    active: mapper,service

(5)其他原因:Resources资源目录下的application.ymlapplication.properties 的默认名称有被修改,导致程序启动时主启动类的配置文件无法被加载。这时需要修改回application.yml来才行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

东方神剑2023

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

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

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

打赏作者

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

抵扣说明:

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

余额充值