报错解决: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 问题解决,详细报错信息如下:

***************************
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 (the profiles dev are currently active).

问题背景:在SpringCloud项目下新增了个子SpringBoot微服务,这个微服务只是单纯的数据处理,不需要连接数据库,所以刻意没有做数据库的关联。但是项目启动的时候就报这个错误了,很明显就是数据库的连接信息找不到,但我明明记得建项目的时候特意没有做mysql的相关依赖啊,于是就一步步排查…(SpringBoot版本是2.6+)

1.首先检索一下pom文件中有没有数据库相关的配置,关键字:mysql、mybatis、jdbc…一通查询下来,发现并没有

2.然后看一下yml中有没有数据库的配置,发现也没有

3.其他都没有数据库的元素,但是一启动的时候就报错,就只能从启动类那边下手了,最后定位到启动类注解@SpringBootApplication了,可能在启动的时候就默认加载数据库的配置,程序找不到,就报错了。只需要在注解上去除DataSourceAutoConfiguration就可以了,完美解决!@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

启动类如下:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class MyServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyServerApplication.class, args);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值