springBoot 启动报错: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

原因
其实这个异常在SpringBoot中是一个比较常见的异常,一般是因为SpringBoot自动配置时,检测到我们添加了MySQL、Oracle、Mybatis等和数据库相关的依赖包,结果我们的配置文件中却没有添加数据库相关的配置,比如:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/db?characterEncoding=utf-8
username: root
password: root
解决方法
1. 在 yml 中添加相关配置
2. 在SpringBootApplication注解中进行数据库配置的排除,即@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})。


浙公网安备 33010602011771号