迅速解决FailedtoconfigureaDataSource:‘url‘attributeisnotspecifiedandnoembeddeddatasource

原创
小哥 3年前 (2022-11-07) 阅读数 7 #大杂烩

彻底解决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}) 只需忽略数据库连接。

版权声明

所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除