文章目录

  • 1. 复现问题
  • 2. 分析问题
  • 3. 解决问题
  • 4. 总结问题

1. 复现问题

今天在启动项目时,遇到如下问题:

***************************
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 classAction: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).Disconnected from the target VM, address: '127.0.0.1:64983', transport: 'socket'Process finished with exit code 0

从而,导致项目无法启动:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

2. 分析问题

我们将这句错误Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.翻译为配置数据源失败:“url”属性未指定,无法配置嵌入数据源

但是,我明明在applicaltion.yml中指定了数据源的URL,如下代码所示:

spring:# 指定哪个文件,比如dev.yml local.ymlconfig:activate:on-profile:- @spring.active@#  应用名称application:name: lowCodedatasource:driver-class-name: com.mysql.cj.jdbc.Driverpassword: 123456username: rooturl: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false# 连接池配置druid:# 初始化大小,最小,最大initial-size: 5min-idle: 5max-active: 20# 配置获取连接等待超时的时间max-wait: 60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位毫秒time-between-eviction-runs-millis: 60000# 配置一个连接在池中最小生存时间min-evictable-idle-time-millis: 300000validation-query: SELECT 1 FROM sys_usertest-while-idle: truetest-on-borrow: falsetest-on-return: false

我是不是哪里配置有误?别急,我们再看这句话Reason: Failed to determine a suitable driver class,将其翻译成中文是原因:无法确定合适的驱动程序类

但我已经配置了连接mysql的驱动类,如下代码所示:

<properties><java.version>1.8</java.version><mybatis-version>2.2.2</mybatis-version>
</properties><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope>
</dependency>
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>${mybatis-version}</version>
</dependency>

根据网上资料,说需要配置如下依赖:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

但是,即便配置了该依赖,项目还是无法启动。

于是,再次去看application.yml,忽然想起来,我配置了druid连接池,但没有引入druid依赖。

3. 解决问题

正因为没有引入druid依赖,才报出了上述错误,进而引入如下依赖:

<properties><java.version>1.8</java.version><alibabaDruidStarter.version>1.2.11</alibabaDruidStarter.version>
</properties>
<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>${alibabaDruidStarter.version}</version>
</dependency>

但是,项目还是无法启动,报出同样的错误。

经过反复调试,原来我的上述applicaltion.yml文件配置出现错误,不应该使用如下代码配置active文件:

spring:# 指定哪个文件,比如dev.yml local.ymlconfig:activate:on-profile:- @spring.active@

而是配置成如下代码:

spring:# 指定哪个文件,比如dev.yml local.ymlprofiles:active: @spring.active@

这两种不同配置的区别,可以参考我的这篇文章: https://blog.csdn.net/lvoelife/article/details/126350747

如是修改后,便可成功启动了项目:

【备注】:对spring.active不了解的,可以网上自行查找资料。

4. 总结问题

出现上述错误,一般有如下解决方案:

  1. 查看是否缺少了驱动类。

  2. application.yml的文件是否配置有误:

    • datasource的相关属性是否配置有误,例如:地址值啊,数据库驱动啊,用户名啊,密码啊。

    • 指定文件(@spring.active@)是否有误。

完美解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource的问题相关推荐

  1. 【解决】Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

    SpringBoot项目 Failed to configure a DataSource:'url' attribute is not specified and no embedded datas ...

  2. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource c

    2019独角兽企业重金招聘Python工程师标准>>> spring boot启动报错: Description: Failed to configure a DataSource: ...

  3. 报错信息为:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

    报错信息为:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource ...

  4. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could

    新建了一个Spring boot项目后,启动项目,出现错误: 原因是项目中用到了Mysql数据库,启动前必须配置数据源配置文件 解决方法: 在resources目录下的application.prop ...

  5. 解决 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

    原因:yml或者properties文件没有被扫描到,需要在pom文件中<build></build>添加如下.来保证文件都能正常被扫描到并且加载成功 <!-- 如果不添 ...

  6. Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded 。。。的解决办法

    问题背景: 搭建了Springboot项目之后,初次启动项目,发现项目无法启动.检查依赖都已经导入.依旧报错:"Failed to configure a DataSource: 'url' ...

  7. SpringBoot中“Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datas

    一. 异常现象 我在Spring Boot中关联MySQL.Mybatis进行数据库开发时,按照正常步骤添加了相关数据库的依赖,也进行了必要的数据库配置,结果在项目启动时出现如下异常信息: ***** ...

  8. Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded

    SpringCloud 项目启动出现未能配置数据源 Description:Failed to configure a DataSource: 'url' attribute is not speci ...

  9. springboot 项目启动报错 url' attribute is not specified and no embedded datasource could be configured

    报错信息: Error starting ApplicationContext. To display the conditions report re-run your application wi ...

最新文章

  1. matlab余割平方方向图,基于余割平方赋形波束的宽带微带阵列天线设计
  2. android surfaceview 大小_Android 使用Camera2 API采集视频数据
  3. 90-40-010-源码-CUBE-引擎为MR写入Habse的构建
  4. 【Oracle批量更新】根据一个大表批量更新另一大表的方法比较
  5. hive insert into语句 和 insert overwrite语句
  6. 鸟哥Linux私房菜-读后感想
  7. win10如何打开摄像头_解决win10相机无法使用,相机崩溃问题
  8. matlab 各类符号意义
  9. 浪潮计算机密码,计算机BIOS通用密码大全
  10. 电脑C盘满了怎么办?教您3招快速释放C盘空间
  11. 【对学习现状的总结和思考】
  12. AMBA总线协议 之 APB总线协议
  13. 【Android UI】贝塞尔曲线 ② ( 二阶贝塞尔曲线公式 | 三阶贝塞尔曲线及公式 | 高阶贝塞尔曲线 )
  14. 京东 探索星球瓜分 1000 亿京豆 脚本
  15. C语言math.h详解
  16. Android应用开发五大框架,android 五大应用开发框架是什么
  17. OSX: QuickLook快速预览不工作?
  18. 电脑cpu温度太高解决方案
  19. NB-IoT系列协议
  20. 视频输入输出常用接口

热门文章

  1. 这几个动图告诉你科学的神奇,看完瞬间觉得智商都提高了
  2. C# VS2017中Windows窗体更改图标
  3. Android studio 放大字体
  4. c语言组播源码_CLAA Class C简单组播业务的实现
  5. 联合循环——23(屋顶防雷,盘柜中性点地排)
  6. c语言平均绩点_【干货】你们关心的GPA算法来了!
  7. sql server 设置自动备份
  8. Linux通过vidpid找到摄像头对应的索引
  9. 程序员的工资被严重高估?
  10. 在线绘图网站文图使用教程