报错Failed to configure a DataSource: .. attribute is not specified and no embedded datasource..

当我们用springboot做简单项目,如该项目只是用feign调用其他微服务
可能会遇到这样的报错:(只想解决不想看原因可直接看粗字体
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…
问题分析及解决方案
问题原因: springboot基于约定,默认会自动加载Mybatis加载类,其实是大部分spring - datasource - url没有加载成功,分析原因如下所示.

DataSourceAutoConfiguration会自动加载.

没有配置spring - datasource - url 属性.

spring - datasource - url 配置的地址格式有问题.

配置 spring - datasource - url的文件没有加载.

显然,这里是因为DataSourceAutoConfiguration会自动加载,而因为我们不需要数据源而没有配置相关配置,
所以他因不能成功加载而报错建议你去配置相关信息在这里插入图片描述

所以我们要取消他的自动加载
解决办法:
将引导类@SpringBootApplication()改成:

@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class})
取消自动配置数据源,原因这里很明显了吧
问题解决
二:是否单模块项目且打包方式为pom?

猜你喜欢

转载自blog.csdn.net/weixin_43158695/article/details/105871444
今日推荐