mybatis和mybatis-plus同时使用的坑

 更新时间:2023年05月29日 14:53:27   作者:马格南之鹰  
本文主要介绍了mybatis和mybatis-plus同时使用的坑,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

原项目基于mybatis开发,新功能基于mybatis-plus开发,同时依赖如下两个jar包

  • mybatis-spring-boot-starter
  • mybatis-plus-boot-starter

启动时报错:java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory,详情如下:

Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/mybatis/logging/LoggerFactory
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at com.xxx.XXXApplication.main(XXXApplication.java:24)

解决方法:

删除 mybatis-spring-boot-starter依赖,更新依赖(idea中在pom.xml文件上右键,执行maven->reload project)

启动后错Invalid bound statement (not found)

[TRACEID:] 2021-03-26T10:48:21,900 ERROR [main] c.a.b.c.XXXXDataLoader:31 DefaultRangeDataLoader error info = Invalid bound statement (not found): com.xxx.dao.mapper.XXXMapper.xxx
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.dao.mapper.XXXMapper.xxx
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:50)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedMapperMethod$0(MybatisMapperProxy.java:101)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.java:100)
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:95)
    at com.sun.proxy.$Proxy250.subscribeSizeStatistics(Unknown Source)

解决方法: 

将服务配置文件中mybatis.mapper-locations的配置挪到mybatis-plus下,样例如下:

原配置如下:

mybatis:
    mapper-locations: classpath:mybatis/*.xml

新配置:

mybatis-plus:
    mapper-locations: classpath:mybatis/*.xml,classpath:/mybatis-plus/*.xml

到此这篇关于mybatis和mybatis-plus同时使用的坑的文章就介绍到这了,更多相关mybatis和mybatis-plus同时使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Spring Boot多个定时任务阻塞问题的解决方法

    Spring Boot多个定时任务阻塞问题的解决方法

    在日常的项目开发中,往往会涉及到一些需要做到定时执行的代码,下面这篇文章主要给大家介绍了关于Spring Boot多个定时任务阻塞问题的解决方法,需要的朋友可以参考下
    2022-01-01
  • java 格式化输出数字的方法

    java 格式化输出数字的方法

    在实际工作中,常常需要设定数字的输出格式,如以百分比的形式输出,或者设定小数位数等,现稍微总结如下
    2014-01-01
  • Spring MVC+FastJson+hibernate-validator整合的完整实例教程

    Spring MVC+FastJson+hibernate-validator整合的完整实例教程

    这篇文章主要给大家介绍了关于Spring MVC+FastJson+hibernate-validator整合的完整实例教程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2018-04-04
  • Springmvc ViewResolver设计实现过程解析

    Springmvc ViewResolver设计实现过程解析

    这篇文章主要介绍了Springmvc ViewResolver设计实现过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-10-10
  • 如何用java编写一个rmi

    如何用java编写一个rmi

    RMI能让一个Java程序去调用网络中另一台计算机的Java对象的方法,那么调用的效果就像是在本机上调用一样。下面我们来详细了解一下吧
    2019-06-06
  • ELK搭建线上日志收集系统

    ELK搭建线上日志收集系统

    ELK日志收集系统进阶使用,本文主要讲解如何打造一个线上环境真实可用的日志收集系统,有了它,你就可以和去服务器上捞日志说再见了
    2022-07-07
  • 关于RocketMQ使用事务消息

    关于RocketMQ使用事务消息

    RocketMQ是一种提供消息队列服务的中间件,也称为消息中间件,是一套提供了消息生产、存储、消费全过程API的软件系统。消息即数据。一般消息的体量不会很大,需要的朋友可以参考下
    2023-05-05
  • IOC 容器启动和Bean实例化两个阶段详解

    IOC 容器启动和Bean实例化两个阶段详解

    这篇文章主要为大家介绍了IOC 容器启动和Bean实例化两个阶段详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-08-08
  • spring boot项目生成docker镜像并完成容器部署的方法步骤

    spring boot项目生成docker镜像并完成容器部署的方法步骤

    这篇文章主要介绍了spring boot项目生成docker镜像并完成容器部署的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-10-10
  • SpringBoot中定义Bean的方法总结

    SpringBoot中定义Bean的方法总结

    在Spring Boot应用程序中,定义Bean是非常常见的操作,它是构建应用程序的基础,pring Boot提供了多种方式来定义Bean,每种方式都有其适用的场景和优势,本文将介绍Spring Boot中定义Bean的几种常见方式,需要的朋友可以参考下
    2023-12-12

最新评论