question
Description:
A component required a bean of type 'com.course.server.mapper.TestMapper' that could not be found.
Action:
Consider defining a bean of type 'com.course.server.mapper.TestMapper' in your configuration.
solve
I used mybatis, and I forgot to add the @Mapper annotation in the mapper layer. After adding it, it will be fine.
Other cases:
- The service layer should add @Service
- If the annotations are all added, it is also related to the directory level of the scan package configuration, pay attention to check
After using @mapper, there is no need to set the scanning address in the spring configuration. Through the namespace attribute in mapper.xml corresponding to the relevant mapper class, spring will dynamically generate beans and inject them into ServiceImpl
Reference link: The role of @Mapper