一、背景

  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. task_struct原码解读

    该结构体在linux中的路径为如下,如果是本地也可以根据以下子目录找到task_struct结构体,该结构体源码中在600多行 https://github.com/torvalds/linux/bl ...

  2. jsfuck-原理

    jsfuck真的fuck,第一眼就是WTF?? Example The following source will do an alert(1): [][(![]+[])[+[]]+([![]]+[] ...

  3. java线程基础巩固---数据同步引入并结合jconsole,jstack以及汇编指令认识synchronized关键字

    对于多线程编程而言其实老生成谈的就是数据同步问题,接下来就会开始接触这块的东东,比较麻烦,但是也是非常重要,所以按部就班的一点点去专研它,下面开始. 数据同步引入: 这里用之前写过的银行叫号的功能做为 ...

  4. White-Label Apps

    转载:https://www.vendasta.com/blog/white-label-apps What are white-label apps? White-label apps are ap ...

  5. 微信小程序aes前后端加密解密交互

    aes前后端加密解密交互 小程序端 1. 首先引入aes.js /** * [description] CryptoJS v3.1.2 * [description] zhuangzhudada so ...

  6. java 枚举类(简单使用)

    直接上代码 用法一(常量): package com.ou.test; import com.sun.corba.se.impl.util.SUNVMCID; public class Enum { ...

  7. 第十一章 前端开发-jQuery

    11.4.0 jQuery 11.4.1 基本知识 定义: jQuery是一个快速,小巧,功能丰富的JavaScript库 作用:它通过易于使用的API在大量浏览器中运行,使得HTML文档遍历和操作, ...

  8. Java-生成缩略图工具类

    import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingH ...

  9. 微信小程序---密码输入

    设计支付密码的输入框 效果如下: 源码:github地址:https://github.com/fiveTree/-_- 干货: <view class="pay"> ...

  10. windows安装解压版postgresql

    1.postgresql解压版下载 2.将下载的postgresql-12.1-1-windows-x64-binaries.zip解压 data文件夹后面初始化数据库时手动创建的 3.初始化数据库 ...