關於idea在springboot啓動時報錯Cannot determine embedded database driver class for database type NONE解決辦法

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

場景一:  我只是想使用idea讀取 application.properties或者application.yml裏配置的屬性值時然後在控制檯輸出瞧瞧,因爲聽說自動讀取會很拽的樣子,不過不連接數據庫啓動springboot會出現:

  1. 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,此時如果運氣不好就會碰到和上面一樣的錯誤,

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

                                   
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章