报错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 datasource could be configured.Reason: Failed to deternine a suitable driver class

问题:写了一个用于数据库数据同步的项目,在本地部署测试均正常,服务器也正常,因源代码逻辑不严谨更新了部分代码,重新部署时发现,本地一切正常的项目,但部署至服务器项目无法启动,且报错信息一闪而过,黑屏终端自动关闭,通过截屏方式获取报错信息如下:

报错:

Failed to configure a DataSource: 'url’ attribute is not specified and no embedded

datasource could be configured.
Reason: Failed to deternine a suitable driver class

Consider the following:

If you want an embedded database (H2,HSQL or Derby), please put it on t

he classpath.

If you have database settings to be loaded from a particular profile you

may need to activate it <no profiles are currently active).

解决方法:

方法1:

参考:报错[已解决]: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 -CSDN博客

看博主解决思路突然想到自己在更新版本时也另外导入了其他依赖,找到后删除,问题解决,项目运行正常

删除以下依赖

mybatis-spring-boot-starter 原理分析;

参考:mybatis-spring-boot-starter 原理分析-CSDN博客

引入mybatis-spring-boot-starter模块之后,其可以:

● 自动检测DataSource

● 使用SqlSessionFactoryBean注册SqlSessionFactory 实例,并设置DataSource数据源

● 基于SqlSessionFactory自动注册SqlSessionTemplate实例

● 自动扫描@Mapper注解类,并通过SqlSessionTemplate注册到Spring Context中

方法2:

看报错信息是数据库连接问题,在我的代码里没有在.yml中配置数据库信息和注解结合使用的方法,而是在application.properties文件中配置,然后在impl文件中进行引用,所以无需在项目启动时就连接数据库,

因此在DataSynchronizationApplication.java启动文件中,可以将@SpringBootApplication修改为@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})就可以启动的时候不需要连接数据库。

到此问题解决,仅记录自己学习过程中的问题与解决方式,如有不妥,请各位大神指导。

  • 45
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值