问题
springboot项目报错
Cannot determine embedded database driver class for database type NONE
具体如下:
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).
其中,相关yml文件如下:
spring:
redis:
host: localhost
password:
port: 6379
timeout: 1000
pool:
max-idle: 100 # 连接池中的最大空闲连接
min-idle: 1 # 连接池中的最小空闲连接
max-active: 1000 #连接池最大连接数(使用负值表示没有限制)
max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制)
这里没有配置mysql的链接,是因为该项目不需要与mysql进行交互。
原因
springboot 要创建一个DataSource对象:
-
尝试查找dataSourceClass,如果找到,条件就成立。那么debug下,可以发现查找到的dataSourceClass是:org.apache.tomcat.jdbc.pool.DataSource 。
-
那么再看下org.apache.tomcat.jdbc.pool.DataSource这个类是从哪里来的呢?
-
从maven依赖树可以看到,依赖是来自:spring-boot-starter-jdbc。所以是应用依赖了spring-boot-starter-jdbc,但是并没有配置DataSource引起的问题。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
解决
pom中删除如下依赖(因为该依赖向上依赖了spring-boot-starter-jdbc
)
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>