SpringBoot没有配置数据源导致SpringBoot无法启动

今天在写一个小Demo的时候出现了一个问题,直接导致SpringBoot项目无法启动

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).

在这里插入图片描述

导致这个异常的原因是这样子的,我这个小 Demo 是用 SpringBoot 框架实现一个不连接数据库,然后前端传值到后台,最后在后台直接判断传过来的值是否等于我规定的值。以前使用 Servlet 写的时候没有出现过这个问题,但最后查出来了原因,原因在于我导了 MyBatis 的依赖

mcgIR5n8ePLTVHG

导入了这个依赖后,SpringBoot 会自动去配置文件里面找数据库的配置,找不到就给你报错。

解决方案:这里有两个解决方案,第一个是 把这个依赖注释掉;第二个是 在启动类里面的 @SpringBootApplication 注解后面加上(exclude = DataSourceAutoConfiguration.class),最终的结果是@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

意思是不加载 DataSourceAutoConfiguration 这样一个类

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值