Reason: Failed to determine a suitable driver class 项目启动报错解决

这篇具有很好参考价值的文章主要介绍了Reason: Failed to determine a suitable driver class 项目启动报错解决。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

今天遇到了这个问题,因为在网关服务的pom.xml文件中引用了其他模块,而其他模块有DataSource相关的依赖,我的配置文件中没有对应的配置,所以报错了。顺便总结一下吧

报错信息如下:

2021-04-01 10:47:19.255 ERROR 3249 --- [  restartedMain] 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 0

排查错误的原因:

情况一:服务没有用到DataSource,但是pom.xml中引入了jdbc或者 Mybatis相关的依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

情况二:服务没有用到DataSource,pom.xml引入其他模块,而其他模块中有jdbc或者和mybatis相关的依赖.

比如网关模块中引入了leadstore-user这个模块,而leadstore-user这个依赖里面有mybatis-plus相关的依赖,网关的application.yml文件中又没有配置DataSource

        <dependency>
            <groupId>com.heima</groupId>
            <artifactId>leadstore-user</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>

这样的话,在springboot工程启动的时候回自动初始化DataSource相关的信息,但是却找不到,则会报错

解决方案:

方案一:1. 首先检查第一种情况,排查pom.xml中的依赖,把jdbc和mybatis相关的依赖删除;如果是需要用到的,在配置文件中添加相对应的配置,如果有添加了的话,检查一下url有没有错误

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/leadstore_user?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useUnicode=true&useSSL=true
    username: root
    password: root

另外需要注意一下的: 

1. jar包可能冲突:使用maven-helper检查jar包是否冲突,冲突就更换下jar包版本

Reason: Failed to determine a suitable driver class 项目启动报错解决

 

2. MySQL版本过高的话,application.yml文件中配置 url: &useSSL=false 会有没用的情况 

方案二:不在application.yml中配置,在启动类的@SpringBootApplication加上(推荐):

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class })

或者在application.properties里配置:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration

大概这样,遇到其他问题再回来补充。文章来源地址https://www.toymoban.com/news/detail-446477.html

到了这里,关于Reason: Failed to determine a suitable driver class 项目启动报错解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • DBeaver连接sqlserver报错“Reason: can‘t load driver class ‘com.microsoft.sqlserver.jdbc.SQLServerDriver‘”

    报错详情: Can\\\'t create driver instance Error creating driver \\\'MS SQL Server / SQL Server\\\' instance. Most likely required jar files are missing. You should configure jars in driver settings. Reason: can\\\'t load driver class \\\'com.microsoft.sqlserver.jdbc.SQLServerDriver\\\' Error creating driver \\\'MS SQL Server / SQL Server\\\' instance. Most likely required jar

    2024年02月05日
    浏览(42)
  • SpringBoot微服务项目报错:Failed to process import candidates for configuration class [springfox.boot...

    [main] ERROR org.springframework.boot.SpringApplication - Application run failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [springfox.boot.starter.autoconfigure.OpenApiAutoConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [springfox/document

    2024年01月17日
    浏览(57)
  • 【SpringBoot中使用SLE4J日志框架启动报错:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinde】

    1.1 出现的问题 SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 1.2 原因分析 检查自己的maven依赖,发现已经引入了slf4j-api了,这是为什么呢?其原因是,SLF4J本身

    2024年02月13日
    浏览(24)
  • Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [properties]

    Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [properties]: Root mapping definition has unsupported parameters:   我们在使用RestClient创建索引库时出现了这个错误。 可以检查一下 CreateIndexRequest 类型变量request 是否导入正确的包 有两个同名的包,我们选择: 创建的索引

    2024年02月11日
    浏览(29)
  • elasticsearch创建索引报[type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]......

    小伙伴们,你们好,我是老寇 经过反复排查,发现是安装的pinyin和ik分词版本不对,只需要修改成与es版本一致即可 es 7.6.2 举例 1.在windows界面用压缩软件打开elasticsearch-analysis-ik-7.6.2.jar 2.将pom.xml拖出到桌面 3.修改版本 4.将pom.xml放回压缩包( 原路放回 ) 5. elasticsearch-analysis

    2024年02月13日
    浏览(21)
  • Spring boot 项目Kafka Error connecting to node xxx:xxx Kafka项目启动异常 Failed to construct kafka consumer

    新建了一个springBoot集成Kafka的项目配置好yml后发现启动失败: 下面是Kafka配置: node1:9092,node2:9092,node3:9092 是kafka的主机名,我是由之前的旧项目(非springBoot)迁移到新建项目的,所以链接名就直接抄过来了。 我以为是链接出了问题,我就换成ip形式,把node1:9092,node2:9092,node

    2023年04月08日
    浏览(22)
  • 解决 libGL error: failed to load driver: swrast

    运行图形工具报错: $ gvim libGL error: No matching fbConfigs or visuals found libGL error: failed to load driver: swrast 网上查资料说,安装Mesa-32bit 软件包可以解决。所以安装了很多mesa i386的软件包,如下: 安装完成后,确实好了。

    2024年02月12日
    浏览(34)
  • Failed to initialize NVML: Driver/library version mismatch

    昨天跑代码,cuda还能好好的to(device),今天就不行了。输出 torch.cuda.is_available() 显示False,运行代码出现以下错误: 在终端输入nvidia-smi出现了以下错误 上网查询,发现了许多解决方法。为了更好的解决问题,并且避免再次出现,我对这些方法进行了简单的整理。希望能够帮到

    2024年02月02日
    浏览(33)
  • Failed to initialize NVML: Driver/library version mismatch (解决)

    运行 nvidia-smi 报错: 只需一步:下载一个安装包,运行一个命令来重新安装 cuda driver 和 cuda toolkit (在一个包里)。 到这里:https://developer.nvidia.com/cuda-toolkit-archive 选择要下载的安装包。 点击要下载的版本后,下载对应的安装包,这个安装包包括 Driver(驱动) Cuda toolkit (工具

    2024年02月16日
    浏览(38)
  • PCB解决(Failed to add class member)问题

    今天画板子时候发现一个之前没遇到的问题,就是在生成PCB时候会提示你Failed to add class member : XXX(未能添加类成员:XXX),然后同时会发现有些器件会提示不知道引脚,问题如图所示: 查了一下网上没有发现问题原图, 倒是有两个解决方案,一个是在创建一个PCB文件,在重新

    2024年02月13日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包