Spring boot項目剛搭建好,啓動測試,出現Failed to configure a DataSource

    今天新搭建了一個springboot+gradle框架,然而,剛搭建好運行的時候,就報了一個錯誤:
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2018-11-19 13:59:44.020 ERROR 1256 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

    問過度娘娘後,才知道,需要在啓動類的@EnableAutoConfiguration或@SpringBootApplication中添加exclude= {DataSourceAutoConfiguration.class},排除此類的autoconfig。啓動以後就可以正常運行。
這是因爲添加了數據庫組件,所以autoconfig會去讀取數據源配置,而我新建的項目還沒有配置數據源,所以會導致異常出現。
    照着改過之後,再次運行,就可以了,親測。。。

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