彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

"本文档详细记录了SpringBoot应用在启动时遇到的'Failed to configure a DataSource'错误,该错误源于未指定数据库连接URL。错误日志显示了Bean创建异常和无法确定合适的数据库驱动类。解决方案是通过在主启动类上使用@SpringBootApplication(exclude={DataSourceAutoConfiguration.class}
摘要由CSDN通过智能技术生成

彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

错误描述:

2022-08-19 09:56:55.641  WARN 47976 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2022-08-19 09:56:55.645  INFO 47976 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-08-19 09:56:55.657  INFO 47976 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-19 09:56:55.743 ERROR 47976 --- [           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).


Process finished with exit code 1

在这里插入图片描述

错误原因:

springboot自动装配,一开始是直接默认连接数据库的即错误中提示的datasource,而我这里并没有连接数据库,没有给它datasource,所以就会找不到datasource,那么就出现了错误。

解决办法

将主启动类的注解@SpringBootApplication修改为@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})忽略到数据库连接即可。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值