這兩天新開一個springboot + mybatis項(xiàng)目,啟動時報錯提示
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.xxx.xxx.wechat.service.impl.WeChatServiceImpl required a bean of type 'com.xxx.xxx.wechat.dao.WeChatDao' that could not be found.
Action:
Consider defining a bean of type 'com.xxx.xxx.wechat.dao.WeChatDao' in your configuration.
Process finished with exit code 1
dao代碼如下
WeChatDao
啟動類代碼如下
啟動類
這妥妥的不科學(xué)啊视卢,在同一個路徑包下的其它service和controller都掃描注冊成功了,獨(dú)獨(dú)@Repository失敗弟孟。后經(jīng)研究發(fā)現(xiàn)膝擂,使用@MapperScan代替@ComponentScan就能解決這個問題。
解決后
他們的區(qū)別如下:
@ComponentScan是組件掃描注解鸳慈,用來掃描@Controller @Service @Repository @Component這類,主要就是從掃描路徑中找出標(biāo)志了需要裝配的類到Spring容器中
@MapperScan 是掃描mapper類的注解