springboot未进行数据库连接却报数据库连接错误

错误描述:

springboot开发时某个服务未用到数据库操作,也没有进行数据库的配置,却报出如下数据库连接错误


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

2022-04-08 09:38:21.513 WARN 13816 — [ Thread-7] c.a.n.common.http.HttpClientBeanHolder : [HttpClientBeanHolder] Start destroying common HttpClient
在这里插入图片描述

解决:

向上翻看错误信息,发现关键所在
在这里插入图片描述
2022-04-08 09:38:21.437 WARN 13816 — [ main] onfigReactiveWebServerApplicationContext : 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/DataSourceConfigurationHikari.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

springboot自动配置包

mybatisplus里有
在这里插入图片描述
,如果你使用其他数据库连接池,也会自动进行配置
在这里插入图片描述

这是因为mybtis-plus包里有数据源自动配置类,他会到springboot配置文件中自动寻找配置信息,当你引入这个包的时候,但是却不进行配置信息那么就会报错。所以解决办法有两个如下:

1.在该服务中把没有用到的mybatisplus和durid连接池依赖去掉
在这里插入图片描述

我这里是把引入工具包中的依赖给排除,如果是在pom文件中直接引入的依赖,删除即可。

在这里插入图片描述

可以在这直接把两个自动配置类给排除

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值