1. 程式人生 > >Mybatis與springboot專案啟動時出現Field XXX in com.xxx that could not be found

Mybatis與springboot專案啟動時出現Field XXX in com.xxx that could not be found

Mybatis與springboot專案,啟動時報錯,詳細的錯誤如下:

Field xxx in com.xxxl required a bean of type ‘xxx’ that could not be found.
Action:
Consider defining a bean of type ‘xxx’ in your configuration.

原因是bean裝配失敗,springboot掃描時沒有找到DAO 的@Mapper對應的介面。
解決方法:
在啟動類前加上:

@MapperScan(basePackages = { "mapper所在的包路徑" })

掃描xx.xx.mapper包下的所有mapper