1、問題
今天在使用springboot整合mybatis時發現報了一個很奇怪的錯誤。找不到數據庫,報錯信息如下:
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
於是檢查了一下application中的datasource配置,乍看之下並沒有發現錯誤,配置信息如下:
datasource:
url: jdbc:mysql://localhost:3306/XX?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
2、解決問題
於是找度娘解決問題,百度大多是說在啓動類修改註解,我的原註解如下圖1所示
修改爲2之後依然報錯,如下圖所示,
報錯:Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required。
還是數據庫的配置問題,於是找出之前的項目仔細比對,發現application.yml配置錯誤,正確配置如下:
然後再次啓動
發現可以正常啓動了…