一、背景

  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. 基础数据 补充 set() 集合 深浅拷贝

    一  对字符串的操作 li = ["张曼玉", "朱茵", "关之琳", "刘嘉玲"] s = "_" ...

  2. Jmeter (一) 安装

    https://blog.csdn.net/ls1792304830/article/details/52718177 一.准备工具 1.Windows 操作系统 2.jmeter 3.JDk 依赖环 ...

  3. C++第三次作业--作用域

    作用域 任何一种语言最基本的部分就是变量,而变量有两个非常重要的特性,作用域和生存期. 定义 作用域是变量的一个属性,某个变量在代码中有效的区域为该变量的作用域. 函数原型作用域 函数声明参数从参数声 ...

  4. 查看电脑物理地址(MAC)方法

    首先打开电脑,按ctrl+R键,将会出现以下界面 然后直接点击确认即可,会出现管理员界面,如下 我们现在有两种查看MAC地址的方法: 方法一:.直接输入ipconfig/all(或者输入ipconfi ...

  5. kotlin面向对象实战~

    有了java的面向对象的基础,其实对于kotlin这块的东东比较好理解,所以这里以洗衣机洗衣服为例,对面向对象进行一下实战,下面开始. 洗衣机初步: 首先先新建一个洗衣机类: 然后里面先定义基本属性: ...

  6. 点击startup.bat启动tomcat出现乱码

    找到tomcat目录下的/conf/logging.properties添加语句:java.util.logging.ConsoleHandler.encoding = GBK重启tomcat 问题解 ...

  7. HTML5的快捷方式

    ctrl + /  单行注释 ctrl + shift + /   块注释 ctrl + shift + “+”   展开 ctrl + shift + “-”  折叠 ctrl + alt + L  ...

  8. 使用powershell的remove

    使用Remove-Module -Name Functions2 只是移除当前会话的模块 并且Import-Module -Name Functions2与 Remove-Module -Name F ...

  9. CF875F Royal Questions[最大生成基环树森林]

    这题这场比赛一堆人秒切..果然还是我太菜了吗 题意:二分图,右边$m$个点每个点$i$向左边有且仅有两条连边,边权都是$a_i$.求最大匹配. 一个朴素思想,二分图匹配,用贪心带匈牙利搞一搞,但是复杂 ...

  10. vue组件,vue补充和总结,JS循环遍历和加减运算、类型转换补充

    目录 一.vue中的组件 1. 组件的概念 2. 组件分类 3. 组件的特点 4. 组件的定义 5. 组件化 (1)用法和注意 (2)数据组件化实例 6. 组件传参--父传子 (1)用法和注意 (2) ...