关于SpingBoot整合MP中Mapper相关的错误1

错误:Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘baseMapper’;

1.出现的问题:创建userServiceImpl的bean失败

2.解决过程

  • 解决过程:

首先看UserMapper

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiren.gt.entity.User;
import org.mapstruct.Mapper;
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

起初以为是Mapper注解的包导错了引起的,进行修改

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiren.gt.entity.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserMapper extends BaseMapper<User> {

}

但是还是出现上面的问题,很费解,所以尝试不使用Mapper注解,使用@Repository注解,但是使用@Repository这个注解就需要在启动类上配置下@MapperScan,因为@Repository只是个标识,表示这个是bean对象,如果想要这个接口被扫描到需要使用@MapperScan

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiren.gt.entity.User;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper extends BaseMapper<User> { }
@SpringBootApplication(scanBasePackages = {"com.qiren.gt"})
@MapperScan(basePackages = {"com.qiren.gt.mapper"})
public class ServiceAclApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceAclApplication.class, args);
    }
}

这回错误解决了,但是还是有一点不清楚,@Mapper的作用相当于@Repository+@MapperScan的作用,但是有的时候会出现bug(这个目前还不清楚为什么),这是个解决方案,可以先用着

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值