SpringBoot启动报错:Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and

绝地灬酷狼 2021-09-22 13:52 360阅读 0赞
  1. 今天倒腾了一下自己的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’

上面还有一条异常信息:

  1. 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
  2. 20
  3. 综合来看确定是在项目中使用了数据库相关的组件,但是没有配置数据源信息。看了一下项目pom文件,不知道自己什么时候引入了spring-boot-starter-jdbc这个依赖包:
  4. <dependency>
  5. <groupId>org.springframework.boot</groupId>
  6. <artifactId>spring-boot-starter-jdbc</artifactId>
  7. </dependency>

解决问题方法,如果你需要用到数据库组件,那么就需要配置一下数据源相关的信息;如果暂时不需要数据库组件,那么可以在项目启动类上,这样写@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})就可以了;或者就是注释掉pom文件中用到的数据库相关starter组件引入,重新更新一下maven项目依赖也可以。

发表评论

表情:
评论列表 (有 0 条评论,360人围观)

还没有评论,来说两句吧...

相关阅读