這篇文章主要介紹了Spring boot 啟動提示數(shù)據(jù)源錯誤怎么辦,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)于2013年成立,先為沈北新等服務(wù)建站,沈北新等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為沈北新企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
在啟動 Spring Boot 的項目的時候提示數(shù)據(jù)源未配置的錯誤。
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 會提示你完整的導(dǎo)致啟動錯誤的信息是:
*************************** 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
從上面的啟動信息來看,已經(jīng)說得非常清楚了,就是因為你配置了 Spring 的數(shù)據(jù)組件,但是你沒有配置相應(yīng)的數(shù)據(jù)源。
因為這個會導(dǎo)致你的啟動失敗。
有下面的集中解決辦法:
最簡單的解決辦法就是在依賴中添加 H2 的數(shù)據(jù)庫,如果你使用 Spring Batch 的話,這個組件也是需要的,因為 Spring 會使用 H2 為數(shù)據(jù)源。
如果你已經(jīng)添加了數(shù)據(jù)庫驅(qū)動,例如你添加了 MySQL 的數(shù)據(jù)庫驅(qū)動。
那么你需要制定 Mysql 的數(shù)據(jù)庫連接參數(shù)。
spring.datasource.url=jdbc:mysql://localhost:3306/myDbspring.datasource.username=user1spring.datasource.password=passspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
你可用在啟動的時候不載入數(shù)據(jù)源配置。
可用在啟動類上面,添加下面的注解。
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
你也可以在啟動配置文件上面,添加下面的內(nèi)容,這樣能夠保證你在啟動的時候不載入數(shù)據(jù)源配置類。
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAuto
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Spring boot 啟動提示數(shù)據(jù)源錯誤怎么辦”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
標題名稱:Springboot啟動提示數(shù)據(jù)源錯誤怎么辦
文章鏈接:http://www.rwnh.cn/article0/pgcoio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、企業(yè)網(wǎng)站制作、網(wǎng)站設(shè)計、電子商務(wù)、ChatGPT、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)