springboot+mybatis(mybatisplus)配置遇到的问题记录

1、项目启动时报错,大概意思是@Autowired引用mapper时必须写(required = true)。

原因是:没有在启动类添加

@MapperScan("com.*.mapper")

2、项目启动报错找不到mapper

启动类添加了@MapperScan(“com.*.mapper”)也不生效:
报错信息如下:

 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mailConsumer': Unsatisfied dependency expressed through field 'msgLogService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'msgLogServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'msgLogMapper' defined in file [D:\****\target\classes\com\SpringBoot\*\mapper\MsgLogMapper.class]: Invocation of init method failed; nested exception is java.lang.NullPointerException

①首先排除mapper-locations的问题

mybatis-plus.mapper-locations= classpath:mybatis/*Mapper.xml
#mybatis.mapper-locations= classpath:mybatis/*Mapper.xml

②排除第一种,还有第二种情况。原因是缺少以下jar包

 <dependency>
       <groupId>org.mybatis.spring.boot</groupId>
       <artifactId>mybatis-spring-boot-starter</artifactId>
       <version>2.1.3</version>
</dependency>

如果是mybatisplus 是:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatisplus-spring-boot-starter</artifactId>
    <version>1.0.5</version>
</dependency>

③一些情况记录

参考了这个博主的文章
https://blog.csdn.net/u013234928/article/details/94060733

我以为下面两个jar包只要引用一个就可以,没想到找了好几个小时原因,结果是这两个必须同时引用才不会报上面的错fo(╥﹏╥)o

<dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>mybatis-plus</artifactId>
      <version>3.3.2</version>
 </dependency>
<dependency>
     <groupId>com.baomidou</groupId>
     <artifactId>mybatisplus-spring-boot-starter</artifactId>
     <version>1.0.5</version>
</dependency>

3、项目可以正常启动,但是调找不到mybatisplus自带的方法。用自带方法的时候报错BindingException

org.apache.ibatis.binding.BindingException: 
Invalid bound statement (not found): com.SpringBoot.
XX.mapper.XXXMapper.insert

原因依旧是缺jar包

<dependency>
     <groupId>com.baomidou</groupId>
     <artifactId>mybatis-plus-boot-starter</artifactId>
     <version>3.3.2</version>
</dependency>

总结: 最终mybatisplus所依赖的jar包总结

 <!-- mybatis plus【开始】-->
 		 <!-- mybatis plus核心依赖【开始】-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatisplus-spring-boot-starter</artifactId>
            <version>1.0.5</version>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.2</version>
        </dependency>
		<!-- mybatis plus核心依赖【结束】-->

        <!-- 自动生成代码的依赖【开始】-->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.2</version>
        </dependency>
        <!-- 自动生成代码的依赖【结束】-->
<!-- mybatis plus 【结束】-->
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值