解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c

这篇具有很好参考价值的文章主要介绍了解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

解决报错 Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.的三种办法

一、问题描述

在初次完成项目的构建后,启动项目时出错,提示信息“ Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured. ” ,这个异常很好理解,直接翻译成中文,一看便知了 “ 配置数据源失败:没有指定’url’属性,也不能配置嵌入式数据源。 ” ,具体的错误内容如下图:

解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url

二、问题的原因

导致这个问题的原因是因为,在 pom.xml 配置文件中,配置了数据连接技术 spring-boot-starter-jdbc 包 ,在启动配置文件时 ,Spring Boot 的自动装配机制就会去配置文件中找,相关的数据库的连接配置信息,如果找不到则抛出异常信息(具体源码就不在这儿分析了,有兴趣的可以自行去查看)。

加入的 JDBC 依赖包 , 如下图:
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url

三、解决办法

解决办法分为三种:

3.1 第一种解决办法

如果先暂时使用不到数据库连接,只是测试搭建的项目是否能正常启动,可以先将该配置依赖项 spring-boot-starter-jdbc 注释掉即可,选中该项配置按快捷键 “ Ctrl + Shift + / ” 即可。
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url
运行成功
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url

3.2 第二种解决办法

在 SpringBoot 应用程序启动时,排除 jdbc 的自动装配机制即可,在程序入口文件中新增配置注解 “ @SpringBootApplication(exclude= DataSourceAutoConfiguration.class ) ” ,如下图:
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url
运行成功
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url

3.3 第三种解决办法:

在开发库或者本地库中,如果有可用的临时数据库,可以先配置该库为暂时的数据库即可,在 application.yml 配置文件中,加入如下图配置内容:
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url
修改配置后,测试是否能正常启动,如下图:
解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c,bug,SpringBoot,java,spring boot,spring,数据库,url
好了,关于 Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource 的解决办法 就写到这儿了,如果还有什么疑问或遇到什么问题欢迎提问,也可以给我私信留言哦,我会一一详细解答的。
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。文章来源地址https://www.toymoban.com/news/detail-719142.html

到了这里,关于解决报错 Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource c的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包