https://blog.csdn.net/qq_22076345/article/details/81713430
今天倒腾了一下自己的SpringBoot demo的代码,发现启动报了如下的错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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).
Disconnected from the target VM, address: '127.0.0.1:64670', transport: 'socket'
上面还有一条异常信息:
-
2018-
08-
16
00:
01:
40.097 WARN
12424 --- [ 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
-
20
综合来看确定是在项目中使用了数据库相关的组件,但是没有配置数据源信息。看了一下项目pom文件,不知道自己什么时候引入了spring-boot-starter-jdbc这个依赖包:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
解决问题方法,如果你需要用到数据库组件,那么就需要配置一下数据源相关的信息;如果暂时不需要数据库组件,那么可以在项目启动类上,这样写@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})就可以了;或者就是注释掉pom文件中用到的数据库相关starter组件引入,重新更新一下maven项目依赖也可以。