Reason: Failed to determine a suitable driver class

版权声明:本文为博主原创文章,未经博主允许不得转载。 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.
2018-09-15 17:16:04.227 ERROR 43824 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
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相关的配置,所以出错。

解决方案

  1. 在消费者工程中移除mybatis-spring-boot-starter依赖
  2. 在消费者工程启动时,排除数据源自动配置即可,在SpringBootApplication注解时增加exclude= {DataSourceAutoConfiguration.class}属性,即:
    @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

猜你喜欢

转载自blog.csdn.net/myNameIssls/article/details/82716138
今日推荐