trouble shooting(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 (no profiles are currently active).

 

根因分析

这个报错的可能原因非常多。逆向分析不是件容易事情,尤其是spring框架不是我写的情况下。

 

场景一

一些工程项目没有用到外部存储项目,或者没有用到mysql或者oracle存储。 那么不需要连接数据库。

所以配置文件中没有数据库的配置,但是注解@SpringBootApplication默认会注入数据库的配置项,如果没有找到数据库的配置就报这个错了。

这个场景可以排除数据库配置的注入来解决。

例如:

在@SpringBootApplication中排除其注入

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

 

场景二

场景一的这个方法是暴力的干掉了数据库连接, 在绝大多数的项目工程中,这是不可能, 因为用框架写代码不可能不连接数据库的。

如果配置文件中有正确的数据库配置,还出现这个问题是什么原因呢?

遇到这种情况是模块拆分的时候。

比如,一个项目工程原来只有一个标准的项目工程A,也没有划分过任何模块。

现在要拆分模块。

原来的配置文件对应的模块的pom配置文件中的packaging属性比如说jar,不能说pom,如果是pom就会报错,内容就是本文最上面提到的情形。

 具体解决方案:

将模块的如下配置

<packaging>pom</packaging>

直接去掉或者修改为:

<packaging>jar</packaging>

注意:重要的属性就是packaging打包类型,所有的父级项目的packaging都为pom,packaging默认是jar类型,如果不作配置,maven会将该项目打成jar包

 

posted @ 2020-02-12 17:22  狂奔的骆驼  阅读(169)  评论(0编辑  收藏  举报