zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Python--面向对象编程
    Python--私有
    Python--格式化cookie为字典类型
    Python--异常处理
    Python--加密小练习
    bzoj 1774: [Usaco2009 Dec]Toll 过路费
    lougu T7983 大芳的逆行板载
    bzoj 1083(&vijos 1190): [SCOI2005]繁忙的都市 && bzoj 1601: [Usaco2008 Oct]灌水
    vijos 1083 小白逛公园
    51nod 1766 树上的最远点对
  • 原文地址:https://www.cnblogs.com/lvhouhou/p/13804005.html
Copyright © 2011-2022 走看看