在编写MyBatis-Spring-Boot-Starter示例代码的时候遇到一个奇怪的问题,写了一个Mapper在Controller中使用@Autowire自动装载,却一直提示报错,找不到Mapper这个bean,错误信息如下:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-26 10:10:19.414 ERROR 17337 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userMapper in com.reeson.learn.demo.controller.UserController required a bean of type 'com.reeson.learn.demo.mapper.UserMapper' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.reeson.learn.demo.mapper.UserMapper' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:57324', transport: 'socket'
Process finished with exit code 1
google之后找到答案
@SpringBootApplication(scanBasePackages={
"com.reeson.learn.demo.mapper"})
添加scanBasePackages之后问题解决