僅以此博客來記錄做畢設過程中遇到的坑
後端
1.
報錯
//Field XXX in XXXX required a bean of type XXXX that could not be found
Field udao in com.zyc.service.InitServiceImpl required a bean of type 'com.zyc.mapper.UserMapper' that could not be found.
但是檢查XXX發現@Autowired自動注入並沒有問題,mapper也是mybatisgen自動生成的,也沒有問題。
發現原因
是掃描的包路徑寫錯了,mapper沒有掃描到(之前是複製粘貼上一個項目的哈哈哈)
解決辦法
mapperScannerConfigurer.setBasePackage("com.zyc.mapper");
將掃描mapper路徑改對即可
—————————————————————————— ———————————— —————
2.
報錯
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary
初步判定是mysql驅動的問題,但是我項目是用的springboot,按道理不應該出問題
發現原因
經過百度發現,有許多人遇到一模一樣的錯誤。網友給出的原因是最新的mysql驅動名稱變了
以前的是
jdbc.driverClassName=com.mysql.jdbc.Driver
現在的是
jdbc.driverClassName=com.mysql.cj.jdbc.Driver
解決辦法
改正配置中的名稱即可
—————————————————————————— ———————————— —————
3.
報錯
Exception in thread "main" java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
發現原因
經過百度,有許多人遇到一模一樣的錯誤。網友給出的原因是這是在使用MySQL 8.0以上版本(MySQL連接驅動和版本都是8.0以上)的時候出現的問題錯誤
解決辦法
我們需要在訪問數據庫的Url後面加上以下的語句即可:
?serverTimezone=GMT%2B8
比如我配置中原來是
url: jdbc:mysql://127.0.0.1:3306/loan?useUnicode=true&characterEncoding=utf-8
改成
url: jdbc:mysql://127.0.0.1:3306/loan?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
—————————————————————————— ———————————— —————
4.
用redis時,model層必須實例化
例如
public class User implements Serializable{}
—————————————————————————— ———————————— —————
5.
沒有報錯,但是當java程序往redis中存數時,redis-cli(客戶端)中查不到數字
發現原因
嘗試了一下java程序可以從redis中取出數,又嘗試了一下關閉redis服務器,java會報錯找不到redis。
所以應該是java和redis客戶端沒有查詢同一個redis數據庫,並且java是可以成功往redis中存值的
在redis配置中
redis:
host: 127.0.0.1
port: 6379
pass:
maxIdle: 3000
maxWait: 1000
testOnBorrow: true
database: 12 # 換數據庫
那個database就是用哪個數據庫,這裏用的是12,而在redis客戶端中,登陸redis,默認選擇了數據庫0,如果需要切換到其它數據庫使用select 索引值,如select 1表示切換到索引值爲1的數據庫
解決方法
在redis-cli中select 12,使數據庫和spring的redis配置中database後的數字相同