Spring Boot中mybatis:Field peopleInfoMapper in ‘**’that could not be found.
在搭建使用spring boot编译时出现了如下的问题:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-06-21 09:59:29.486 ERROR 8544 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field peopleInfoMapper in com.exa.demo2.Controller.PeopleController required a bean of type 'com.exa.demo2.Mapper.PeopleInfoMapper' that could not be found.
Action:
Consider defining a bean of type 'com.exa.demo2.Mapper.PeopleInfoMapper' in your configuration.
Process finished with exit code 1.
SpringBoot启动失败,告诉我Bean配置失败,楼主看了看 该用的注解都用上了 这是咋的回事嘞?
PeopleMapper:
Controller:
后来在网上查资料说要用@Mapper注解,才能把问题解决。
解决方案1:使用@Mapper注解
解决方案2:使用@MapperScan注解启动类Demo2Application
这样问题就可以顺利解决了。
原因:在mybatis-spring-boot-autoconfigure的jar包中有一个类 MybatisAutoConfiguration,在这个类中的registerBeanDefinitions方法告诉了我们