springboot启动报错:Failed to configure a DataSource

一、背景

  springboot的出现,让项目搭建变得更方便快捷,同时简化掉很多的样板化配置代码,提高开发效率。

  通过idea生成springboot项目,启动报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could be configured.

通过错误不难看出是因为dataSource的url配置缺失导致,但是新生成的项目并没有使用到jdbc,为什么会报出这个问题呢?

二、分析

其实这就是spring boot最核心的内容:自动配置

由于在生成项目的过程中勾选了mybatis以及mysql,所以pom中引入myBatis的jar包:

spring boot就会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类, 在该类中我们可以看到加载了datasource的相关配置

三、解决

知道问题的原因后,解决方法有两种:

1、配置正确的数据源信息,在application.yml中增加如下内容:

启动项目,成功。

2、在看SpringBootApplication源码的时候发现,其实是有“exclude”属性的,那我们是否可以通过该属性指定排除加载类呢?

答案是肯定的,如下所示

服务启动成功。

原文地址:https://www.cnblogs.com/ecology-lee/p/9984545.html

时间: 2024-08-08 13:56:01

springboot启动报错:Failed to configure a DataSource的相关文章

第一个springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

报错内容具体如下 *************************** 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

springboot 新工程报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

错误日志 ... ... Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-04-02 12:52:47.306 ERROR 22036 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLIC

Spring Boot 2.1.7 启动项目失败,报错: "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured."

一开始按照网上的很多解决办法是: 启动类头部声明@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),但是这样会排除掉我自己的数据库配置, 检查了很多地方都没发现问题在哪里,最后自己猜想不论怎么修改application.yml文件,都不生效,是不是因为这个配置文件就没有被加载到? 带着这个想法我就去网上搜了一下问题,有个问题看到了target目录的作用,就去想了一下是不是application.yml文件没有被

springboot启动报错退出,To display the conditions report re-run your application with 'debug' enabled.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-01-19 12:01:39.870 ERROR 8324 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************APPLICATIO

springboot启动报错:"Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled."

报错内容 java.lang.Object.wait(Native Method)java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41)2019-02-14 14:58:00.326 INFO 17688 --- [ main] Condition

Eclipse启动 报错[Failed to load the JNI shared library jvm.dll

准备要做java服务器,在安装开发环境时,启动Eclipse报错[Failed to load the JNI shared library jvm.dll] 研究了下,造成错误的原因是由于eclipse与jdk的不一致造成的. 我的开发环境是64位windows8 Pro,安装了64位jdk1.6,eclipse却粗物的安装了32位的版本,由于64位和32位匹配不一致,造成了以上错误的发生. 又尝试了一下,32位jdk+64位eclipse也会发生同样的问题. 好了,解决方法很简单,jdk和e

springboot启动报错start bean 'eurekaAutoServiceRegistration' NullPointerException

解决方案参考:https://blog.csdn.net/hhj13978064496/article/details/82825365 我将eureka的依赖包放到了依赖包的最下面,启动报错, 如下: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId&

Springboot启动报错:Failed to determine a suitable driver class

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 原因: 没有配置数据源,但springboot默认启用了数据源配置 解决办法: 启动类添加exclude参数,不启用DataSource 原

JBOSS启动报错Failed to start service jboss.web.deployment.default-host.

14:10:01,487 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.web.deployment.default-host./: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./: Failed to start serv