spring boot 整合mybatis時報錯找不到數據庫

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配置錯誤,正確配置如下:
在這裏插入圖片描述然後再次啓動
在這裏插入圖片描述發現可以正常啓動了…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章