报这样的错误一般会遇到下列几种情况:
情况1:注解的问题,业务实现类加@Service,映射类加@Mapper、启动类上加上@MapperScan(basePackages = "com.kingbal")以及@Resouce
情况2:命名相同,将命名修改不同即可
java
@Resource
KingMapper xMapper;
@Resource
KingbalMapper xMapper;
或者
@Autowired
KingMapper xMapper;
@Autowired
KingbalMapper xMapper;
情况3:由于springboot的版本,降低版本即可
情况4:依赖包引入错误的
java
// 错误的
import jakarta.annotation.Resource;
// 正确的
import javax.annotation.Resource;
问题五:application.yml或者application.properties中的项目目录路径完全一致即可
java
mybatis:
mapper-locations: classpath:mapper/kingbal*.xml
type-aliases-package: com.king.kingbal.pojo
configuration:
map-underscore-to-camel-case: true
或
mybatis-plus:
mapper-locations: classpath:/mapper/kingbal*.xml
configuration:
log-impl: kingbal.log
call-setters-on-nulls: true