• springboot启动报错Failed to configure a DataSource


    2018-11-21 19:43:12.076  WARN 5392 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '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
    2018-11-21 19:43:12.076  INFO 5392 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
    2018-11-21 19:43:12.081  INFO 5392 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
    2018-11-21 19:43:12.122  INFO 5392 --- [           main] ConditionEvaluationReportLoggingListener : 
    
    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2018-11-21 19:43:12.126 ERROR 5392 --- [           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).
    View Code

    spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,而DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean,又因为项目(eureka-server模块和短信模块)中并没有关于dataSource相关的配置信息,所以当spring创建dataSource bean时因缺少相关的信息就会报错。

    解决办法:

    1、在@SpringBootApplication注解上加上exclude,解除自动加载DataSourceAutoConfiguration。
    ---------------------
    作者:迷雾骑士
    来源:CSDN
    原文:https://blog.csdn.net/u010448530/article/details/80840828
    版权声明:本文为博主原创文章,转载请附上博文链接!

    @EnableEurekaServer
    @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    public class EurekaServerApplication {

    public static void main(String[] args) {
    SpringApplication.run(EurekaServerApplication.class, args);
    }
    }

  • 相关阅读:
    vue--vuex详解
    vue2.0的一个小demo,
    vue---子调父 $emit (把子组件的数据传给父组件)
    高阶函数总结
    三个方法(apply、call、bind)
    JS的一些总结(函数声明和函数表达式的区别,函数中的this指向的问题,函数不同的调用方式,函数也是对象,数组中的函数调用)
    原型对象(下)
    案例:贪吃蛇
    原型对象(上)
    案例(拖拽对话框、高清放大镜、自制滚动条、元素的隐藏方式、表格隔行变色、tab切换效果、字符串拼接、刷新评论)
  • 原文地址:https://www.cnblogs.com/xiaodebing/p/9997381.html
Copyright © 2020-2023  润新知