记录排查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:
看博主解决思路突然想到自己在更新版本时也另外导入了其他依赖,找到后删除,问题解决,项目运行正常
删除以下依赖
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})就可以启动的时候不需要连接数据库。
到此问题解决,仅记录自己学习过程中的问题与解决方式,如有不妥,请各位大神指导。