SpringBoot整合Mybatis报错:Consider defining a bean of type ‘xx.xx.xx‘ in your configur

2022-05-07 16:11:34 浏览数 (1)

SpringBoot和mybatis整合完后,如果按照spring的整合习惯,可能会发现一个错误:

APPLICATION FAILED TO START

*************************** Description: Field entFileDao in com.alibaba.serviceImpl.EntFileServiceImpl required a bean of type 'com.alibaba.dao.EntFileDao' that could not be found. Action:

Consider defining a bean of type 'com.alibaba.dao.EntFileDao' in your configuration.

这是由于springBoot启动时,没有扫描到com.alibaba.dao.EntFileDao ,而在com.alibaba.serviceImpl.EntFileServiceImpl中又使用了@autowired private EnfileDao entFileDao进行装配,所以会发现错误,说没有定义。此时需要在springBoot的启动类上,加个注解:@MapperScan("持久层路径"),这样就会扫描到com.alibaba.dao.EntFileDao了。

完整整合步骤可参考:Spring Boot---(8)SpringBoot整合mybatis

0 人点赞