springboot启动报错Cannot determine embedded database driver class for database type NONE解决

it2022-05-05  142

原文:https://blog.csdn.net/Master_Shifu_/article/details/80420099

 

场景一:  我只是想使用idea读取 application.properties或者application.yml里配置的属性值时然后在控制台输出瞧瞧,因为听说自动读取会很拽的样子,不过不连接数据库启动springboot会出现: Cannot determine embedded database driver class for database type NONE  

原因是:springboot启动时会自动注入数据源和配置jpa

解决办法:在@SpringBootApplication中排除其注入

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

正确截图如下:

在自己的Application启动类的注解上加上exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}

场景二:此时我在application.properties或者application.yml文件中配置了数据库的连接信息 1.假设配置连接数据如下

2.配置好之后启动Application,此时如果运气不好就会碰到和上面一样的错误, Cannot determine embedded database driver class for database type NONE   可是我明明是配置了propertice配置文件的,然后还提示我这样做

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).

3.此时我肯定是要连接数据库进行数据交互的, 那么Application启动类的注解上肯定是不需要加上exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}

4.何解??  这不绕到一个死循环里面了吗? 客官,莫急,速效救心丸了解一下,在你的pom依赖里加上这句就够了,重启有惊喜

<dependency>         <groupId>com.h2database</groupId>          <artifactId>h2</artifactId>         <scope>runtime</scope>  </dependency>


最新回复(0)