您好,登錄后才能下訂單哦!
這篇文章主要介紹了Spring boot 啟動(dòng)提示數(shù)據(jù)源錯(cuò)誤怎么辦,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
在啟動(dòng) Spring Boot 的項(xiàng)目的時(shí)候提示數(shù)據(jù)源未配置的錯(cuò)誤。
09:52:08.333 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exceptionorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver classat org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:233) at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:174)
Spring 會(huì)提示你完整的導(dǎo)致啟動(dòng)錯(cuò)誤的信息是:
*************************** 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).Process finished with exit code 1
從上面的啟動(dòng)信息來(lái)看,已經(jīng)說(shuō)得非常清楚了,就是因?yàn)槟闩渲昧?Spring 的數(shù)據(jù)組件,但是你沒(méi)有配置相應(yīng)的數(shù)據(jù)源。
因?yàn)檫@個(gè)會(huì)導(dǎo)致你的啟動(dòng)失敗。
有下面的集中解決辦法:
最簡(jiǎn)單的解決辦法就是在依賴(lài)中添加 H2 的數(shù)據(jù)庫(kù),如果你使用 Spring Batch 的話,這個(gè)組件也是需要的,因?yàn)?Spring 會(huì)使用 H2 為數(shù)據(jù)源。
如果你已經(jīng)添加了數(shù)據(jù)庫(kù)驅(qū)動(dòng),例如你添加了 mysql 的數(shù)據(jù)庫(kù)驅(qū)動(dòng)。
那么你需要制定 Mysql 的數(shù)據(jù)庫(kù)連接參數(shù)。
spring.datasource.url=jdbc:mysql://localhost:3306/myDbspring.datasource.username=user1spring.datasource.password=passspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
你可用在啟動(dòng)的時(shí)候不載入數(shù)據(jù)源配置。
可用在啟動(dòng)類(lèi)上面,添加下面的注解。
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
你也可以在啟動(dòng)配置文件上面,添加下面的內(nèi)容,這樣能夠保證你在啟動(dòng)的時(shí)候不載入數(shù)據(jù)源配置類(lèi)。
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAuto
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Spring boot 啟動(dòng)提示數(shù)據(jù)源錯(cuò)誤怎么辦”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。