版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/myNameIssls/article/details/82716138
Reason: Failed to determine a suitable driver class
错误描述
今天基于SpringBoot2.0
集成Dubbo
,并按分模块的方式划分出了服务提供者和服务消费者,服务提供者工程中包含jdbc连接及提供源数据功能,服务消费者主要通过RPC来远程调用服务提供者的服务。
项目启动过程中,服务提供者可以正常启动,且可以正常访问数据库。服务消费者出现以下的问题:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2018-09-15 17:16:04.227[0;39m [31mERROR[0;39m [35m43824[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.d.LoggingFailureAnalysisReporter [0;39m [2m:[0;39m
***************************
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 class
Action:
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).
错误分析
该问题是由于在消费者项目中引入了mybatis-spring-boot-starter
的依赖,这个依赖会根据自动配置约束自己去配置数据源,而消费者项目中并没有dataSource
相关的配置,所以出错。
解决方案
- 在消费者工程中移除
mybatis-spring-boot-starter
依赖 - 在消费者工程启动时,排除数据源自动配置即可,在
SpringBootApplication
注解时增加exclude= {DataSourceAutoConfiguration.class}
属性,即:
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})