Consider defining a bean of type ‘com.course.server.mapper.TestMapper‘ in your configuration.

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.

insert image description here

Other cases:

  1. The service layer should add @Service
  2. 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

Guess you like

Origin blog.csdn.net/qq_51453356/article/details/125761322