Maven專案中,關於Spring Boot 整合MyBatis時,Service層無法找到mapper介面的問題解決
阿新 • • 發佈:2018-12-31
mybatis:
mapperlocations: classpath:com/xxx/xxx/dao/mapper/*.xml -----掃描對映檔案
config-location: classpath:mybatis-config.xml ------掃描配置檔案
注意:路徑要以/ 分割
3 Mybatis 的核心配置檔案 mybatis-config.xml的配置檔案,雖然Spring Boot已經將資料庫的配置設定好了,但是即使是一個空的配置檔案也要放在resouse目錄根目錄下;
(因為裡面設定 Spring Boot 代替不了的設定:比如 駝峰對映、是否開啟二級快取等重要的設定);
本以為配置完上面已經很完美了,誰知還是太年輕了:
繼續配置:
注意:
1 如果將對映檔案不放在resouse目錄下,則必須在pom中載入:
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource> </resources>
載入到<build>標籤下;
如果此時啟動專案還是找不到mapper,那麼就在啟動類上加上註解:@MapperScan(basePack={""})註解,現在才完美;
啟動--成功;
希望各路大神,糾正 指點 共同進步