按筆者 Spring Boot 2 實踐記錄之 MySQL + MyBatis 配置 中的方式,若是想正確運行,須要在 Mapper 類上添加 @Mapper 註解。html
可是加入此註解以後,啓動時會出現以下警告:mybatis
Skipping MapperFactoryBean with name 'xxxMapper' and 'tk.mybatis.xxx.mapper.xxxMapper' mapperInterface. Bean already defined with the same name! No MyBatis mapper was found in '[tk.mybatis]' package. Please check your configuration.
雖然不影響運行,可是對於追求完美的童鞋而言,倒是小有遺憾。app
兩條信息各自對應了一個問題,逐條解決便可。less
第一個問題是由 Mapper 註解引發的,將其去掉。可是這樣一來,第二個問題所指出的找不到 mapper 包的問題,就會引發 Mapper bean 找不到的問題。post
嗯,在配置中添加 Mapper 掃描的基礎包便可,在配置類上方添加以下註解:url
@MapperScan(basePackages = "tk.mybatis.xxx.mapper")
完美解決!spa