一、背景

  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”属性的,那我们是否可以通过该属性指定排除加载类呢?

答案是肯定的,如下所示

服务启动成功。

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

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

    新建了一个springboot项目报一下错误: Failed to configure a DataSource: 'url' attribute is not specified and no em ...

  2. springboot启动报错Failed to configure a DataSource

    2018-11-21 19:43:12.076 WARN 5392 --- [ main] ConfigServletWebServerApplicationContext : Exception e ...

  3. springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde

    springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde 创建 ...

  4. springboot项目启动报错 Failed to configure a DataSource: 'url' attribute is not specified and no embedde

    参考:https://blog.csdn.net/Coyotess/article/details/80637837

  5. Spring boot 启动报错 Failed to auto-configure a DataSource

    1.Spring boot 启动报错 Failed to auto-configure a DataSource 参考资料https://blog.csdn.net/liuyinfei_java/ar ...

  6. SpringBoot启动报错Failed to determine a suitable driver class

    SpringBoot启动报错如下 Error starting ApplicationContext. To display the conditions report re-run your app ...

  7. Spring Boot错误——SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    背景 使用Spring Cloud搭建微服务,服务的注册与发现(Eureka)项目启动时报错,错误如下 *************************** APPLICATION FAILED T ...

  8. SpringBoot 2.0 报错: Failed to configure a DataSource: 'url' attribute is not specified and no embe

    问题描述 *************************** APPLICATION FAILED TO START *************************** Description ...

  9. 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}),但是这样会排除 ...

  10. Spring boot&Mybatis 启动报错 Failed to auto-configure a DataSource

    *************************** APPLICATION FAILED TO START *************************** Description: Fai ...

随机推荐

  1. Ubuntu 16.04 装机后如何永久更改ulimit和修改MySQL的存储路径datadir

    Ubuntu 16.04 装机后的配置要点: 1. 网络的配置 2. 更改源列表 3. 永久更改ulimit ulimit限制着程序打开文件的数目,默认情况下为1024,作为服务器使用时,这个数字往往 ...

  2. 手机 简易浏览器 WebView的基本使用 返回 缓存 进度条

    public class MainActivity extends AppCompatActivity { private WebView webView; private String url = ...

  3. Change :hover CSS properties with JavaScript

    I need to find a way to change CSS :hover properties using JavaScript. For example, suppose I have t ...

  4. ogg12c 配置

    环境:source 192.168.2.182 : 系统:Windows Server 2012 oracle: Release 12.1.0.2.0 ogg: 12.2.0.2.3 target 1 ...

  5. 函数参数-undefined-默认值-可选参数

    1.函数参数为undefined时,触发参数默认值 2.实参数量 < 形参数量,多余的形参值为 underfined 3.设置可选参数 1)JS中: 检测 undefined :function ...

  6. SpringBoot项目 设置全局跨域

    package com.nf147.policy_project; import org.springframework.stereotype.Component; import javax.serv ...

  7. Oracle查询死锁

    select sample_time,session_id,sql_id,event,sql_plan_hash_value,blocking_session from dba_hist_active ...

  8. MVN 报错1

    找不到mapper映射文件 只打包了下面这些 所以pom.xml文件中添加 <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉. --> <build> ...

  9. zabbix企业微信告警配置教程

    前言: zabbix企业微信告警只需要配置一次就可以使用很久了,但是发现再次配置时,总会有遗忘,很麻烦又要去重新熟悉,所以,现在记录一份详细的配置过程,方便日后再次配置. 1.zabbix_serve ...

  10. 循环数组实现FIFO

    涉及到数据通信的软件开发,不能回避的一点是,设计一个实用高效率的数据缓冲区,例如fifo.今天在做项目时候,需要缓存CAN总线上的数据,然后再需要的时候读这些数据.下边给出我自己设计的,采用循环数组实 ...