zoukankan      html  css  js  c++  java
  • Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    最近在学习新的基于springboot的原生云框架,自己创建项目是遇到报错无法启动,快要搞疯了

    错误日志如下:

    2020-04-02 11:25:19.429 ERROR 145648 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbHealthContributor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributor]: Factory method 'dbHealthContributor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.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
    2020-04-02 11:25:19.486  INFO 145648 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    2020-04-02 11:25:19.628  WARN 145648 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [lettuce-eventExecutorLoop-1-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
     sun.misc.Unsafe.park(Native Method)
     java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
     java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
     java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
     io.netty.util.concurrent.SingleThreadEventExecutor.takeTask(SingleThreadEventExecutor.java:289)
     io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:64)
     io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050)
     io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
     io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
     java.lang.Thread.run(Thread.java:748)
    2020-04-02 11:25:19.633  WARN 145648 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    2020-04-02 11:25:19.704  INFO 145648 --- [           main] ConditionEvaluationReportLoggingListener : 
    
    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2020-04-02 11:25:19.709 ERROR 145648 --- [           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).
    
    
    Process finished with exit code 1

    经过排查发现:

      项目触发了数据源的自动化配置,然而我的项目刚创建,并不属于数据库,也没有配置数据库参数。

    解决方法以下几种

          1、禁用数据源的自动化配置

                 启动类加上以下代码

    @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

       2、application.properties/或者application.yml中添加数据库信息,两者格式不一致,请按文档要求的格式配置,配一个就可以,以下为yml的语法

    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/read_data?useUnicode=true&characterEncoding=UTF-8&useSSL=false
        username: root
        password: 123456
        driver-class-name: com.mysql.jdbc.Driver

    以上为本人遇到的情况,可能还有更多的情况,参考自https://www.cnblogs.com/toutou/archive/2019/08/31/embedded-datasource.html

  • 相关阅读:
    10个最常见的 HTML5 面试题及答案
    YII 的源码分析(-)
    架构师速成5.2-如何掌握综合性技能 分类: 架构师速成 2015-06-30 11:18 405人阅读 评论(0) 收藏
    架构师速成5.1-小学gtd进阶 分类: 架构师速成 2015-06-26 21:17 313人阅读 评论(0) 收藏
    架构师速成4.3-幼儿园要学会查找资料 分类: 架构师速成 2015-06-25 09:08 409人阅读 评论(0) 收藏
    架构师速成4.2-幼儿园要学会如何高效学习 分类: 架构师速成 2015-06-24 09:10 409人阅读 评论(2) 收藏
    架构师速成4.1-幼儿园要学会如何学习(转载自36氪) 分类: 架构师速成 2015-06-24 09:05 114人阅读 评论(0) 收藏
    架构师速成-目录 分类: 架构师速成 2015-06-21 20:48 146人阅读 评论(0) 收藏
    架构师速成7-高中 分类: 架构师速成 2015-06-21 19:17 132人阅读 评论(0) 收藏
    架构师速成6-初中 分类: 架构师速成 2015-06-20 12:08 149人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/icemargin/p/12620346.html
Copyright © 2011-2022 走看看