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 这样一个类

发布了30 篇原创文章 · 获赞 7 · 访问量 1575

猜你喜欢

转载自blog.csdn.net/qq_41946543/article/details/103671987