错误描述:
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文件中直接引入的依赖,删除即可。
可以在这直接把两个自动配置类给排除