原因
其实这个异常在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})。
- springBoot classpath embedded database pleasespringboot classpath embedded database database springboot determine embedded springboot路径classpath line application springboot classpath springboot bootstrap classpath supported springboot classpath fatjar springboot embedded时报unable xbootclasspath springboot classpath jar please test-flag-please-ignore