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

  • 相关阅读:
    【c#.Net】类:面向对象
    【c#.Net】面试题库总结50题
    【c#.Net】C#面试题(.net开发人员必备)100题
    【C#.Net】方法和参数
    如何在Tomcat (6/7/8.0) 安装SSL证书
    ubuntu16.04安装jdk/mysql/tomcat (使用apt-get命令)
    java后台处理解析json字符串的两种方式
    web开发如何使用百度地图API(一)判断点是否在范围内
    ES6的let和var声明变量的区别
    web开发如何使用高德地图API(四)通过AMap.Marker自定义标点
  • 原文地址:https://www.cnblogs.com/lvhouhou/p/13804005.html
Copyright © 2011-2022 走看看