idea中springboot項目連接數(shù)據(jù)庫報錯的原因解析
一.我在運用mybatis下報錯,反復檢查無邏輯問題,下圖為項目結(jié)構(gòu)截圖
二.最后總結(jié)問題如下:
1)報錯代碼:
Caused by: java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:486)
原因:pom.xml文件中mysql依賴版本低(5.1.6),但并沒有在properties或者yml文件中手動添加驅(qū)動如下(沒有添加注釋的driver-class-name)
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true username: root password: root #driver-class-name: com.mysql.cj.jdbc.Driver #driver-class-name: com.mysql.jdbc.Driver
ps:下面兩個配置都可以讓低版本mysql依賴下的項目運行,但第二個會報錯如圖
driver-class-name: com.mysql.cj.jdbc.Driver
driver-class-name: com.mysql.jdbc.Driver
2)
報錯代碼:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.jt.mapper.UserMapper.findAll
原因分析:pom.xml中,依賴mysql為高版本(8.0.22)此時任然報錯檢查properties/yml配置文件中的如下代碼
#加載Mapper映射文件mapper-locations: classpath:/mybatis/mappers/*.xml
到此這篇關于idea中springboot項目連接數(shù)據(jù)庫報錯的原因解析的文章就介紹到這了,更多相關idea中springboot連接數(shù)據(jù)庫報錯內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!
相關文章:
1. Python+unittest+requests 接口自動化測試框架搭建教程2. Java GZip 基于內(nèi)存實現(xiàn)壓縮和解壓的方法3. jsp+servlet簡單實現(xiàn)上傳文件功能(保存目錄改進)4. 存儲于xml中需要的HTML轉(zhuǎn)義代碼5. Springboot 全局日期格式化處理的實現(xiàn)6. 利用CSS制作3D動畫7. 一款功能強大的markdown編輯器tui.editor使用示例詳解8. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程9. SpringBoot+TestNG單元測試的實現(xiàn)10. PHP利用COM對象訪問SQLServer、Access
