spring boot啟動報錯Error starting ApplicationContext(未能配置資料來源)
主要錯誤:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
未能配置資料來源:未指定“url”屬性,也無法配置嵌入式資料來源。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-03 09:47:45.300 ERROR 23160 ---
[ //加入Java開發交流君樣:756584822一起吹水聊天
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:
//加入Java開發交流君樣:756584822一起吹水聊天
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).
原因:
spring boot預設會載入
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
類,DataSourceAutoConfiguration
類使用了@Configuration
註解向spring
注入了dataSource bean。因為工程中沒有關於dataSource
相關的配置資訊,當spring建立dataSource bean
因缺少相關的資訊就會報錯。
兩種解決辦法
1.在Application類上加
`
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
2.配置資料來源:
例如在application配置檔案中:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql:
//ip:埠號/資料庫名稱?
useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
「其他文章」
- 參加Chainlink中國開發者社群ETHDenver #BUIDLathon專案提交,贏取Chainlink專案提交獎勵!
- 思科模擬器pnatlab,華為模擬器ensp橋接本地
- 面試 Google, 我失敗了 | Google 面經分享
- google為什麼使用mono-repo
- android-資料儲存之SharedPreferences的簡單使用(記住密碼)
- 知臨集團從加拿大公共衛生局獲得啟動ALS-4——用於治療金黃色葡萄球菌(包括耐甲氧西林金黃色葡萄球菌(MRSA))感染的小分子藥物——的臨床1期試驗許可
- spring boot啟動報錯Error starting ApplicationContext(未能配置資料來源)
- 【同說】機械轉行前端,半年零基礎自學的心路歷程
- IP地址概述與應用
- keepalived構建高可用叢集
- 反向代理解決80埠數量問題
- Python助力2020高校應屆生就業 獲取2020校園招聘資訊
- 程式碼質量在「內卷時代」的重要性
- Servlet 入門教程
- 手機掃碼解決傳統貸款流程
- 顯著性水平、置信區間、假設檢驗與方差分析知識點總結
- 訊息中介軟體簡介
- 一文教會你什麼執行緒安全以及如何實現執行緒安全
- 再談Java泛型---下
- Microsoft 365 開發:如何使用Graph API 新建 O365 Group Site