1. 程式人生 > >SpringBoot啟動報錯Failed to auto-configure a DataSource 的問題解決!

SpringBoot啟動報錯Failed to auto-configure a DataSource 的問題解決!

今天搭了個springboot的小demo,但是啟動的時候報了這個錯誤:

scription:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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.

1.分析:在新建專案的時候我添加了mysql元件,但是我還沒配置資料來源

2.解決方案:

在啟動類的@EnableAutoConfiguration

或@SpringBootApplication中新增exclude= {DataSourceAutoConfiguration.class},

排除此類的autoconfig。

即:@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

3.重新啟動以後就可以正常執行。