• spring boot启动报错Error starting ApplicationContext(未能配置数据源)


    主要错误:

    Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

      未能配置数据源:未指定“url”属性,也无法配置嵌入式数据源。

    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2019-06-03 09:47:45.300 ERROR 23160 --- [           main] 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).

    由第一幅图知,最先发生错误的地方在创建datasource这个Bean,之后造成dao,service,controller都报错了

    我使用application.properties配置文件时出现此错误(换成application.yml时没有出现此错误)

    原因:

    com.mysql.jdbc.Driver的版本太低,与springboot不兼容(springboot使用的2.3.2.RELEASE)
      <!-- mysql驱动 -->
           <!-- 此版本太低--> 
           <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.18</version>
            </dependency>

    更换以下依赖后正常了

    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.21</version>
            </dependency>

    总结:使用application.properties配置文件时springboot的2.3.2.RELEASE与mysql-connector-java的5.1.18不兼容

    其他可能的原因,又看到这篇写的比较多,评论也多

    查看:

    https://blog.csdn.net/qq_40223688/article/details/88191732

  • 相关阅读:
    互联网商业数据分析(二十七):运营分析(三)用户分层
    鲲鹏服务器上跑dpdk kni bug
    dpdk 网卡顺序
    dpvs ipvsadm.c:114:10: fatal error: popt.h: No such file or directory
    dpvs keepalived编译出错
    ps查看线程所在的cpu + pstack 线程+ strace 线程
    查看内核模块加载时参数
    dpdk kni二
    dpdk eal 参数
    dpdk project gdb
  • 原文地址:https://www.cnblogs.com/lvhouhou/p/13804005.html
Copyright © 2020-2023  润新知