• 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

  • 相关阅读:
    洛谷p1056
    __int64
    杭电2057
    4.4清北学堂Day1 主要内容:数论,数学
    递推的一点理解
    高精度减法
    高精度加法
    p1184高手之在一起
    对于rqy今天讲座的一些理解和看法吧
    PHP.21-商品信息管理
  • 原文地址:https://www.cnblogs.com/icemargin/p/12620346.html
Copyright © 2020-2023  润新知