1. 程式人生 > >Spring boot出現Cannot determine embedded database driver class for database type NONE

Spring boot出現Cannot determine embedded database driver class for database type NONE

文件配置 ati ber local ive support auto clu 排除

在spring boot項目中,我們在pom.xml文件中添加了mysql和mybatis的依賴,我們常常遇到下面這樣的問題:

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 boot在項目啟動的時候會註入數據源,而我們在配置文件中又沒有配置數據庫,因此會報這樣的錯誤。

解決辦法:

1.當然是直接註釋掉pom.xml文件中的mysql和mybatis的依賴,這樣spring boot啟動的時候當然不會註入數據源了,因此也就不會報錯了。

2.在@SpringBootApplication中排除其註入

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

3.直接在配置文件配置一下數據庫連接就好了嘛,多簡單的事,那當然就不會報錯了。

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root

Spring boot出現Cannot determine embedded database driver class for database type NONE