如何解决Mybatis-plus与Mybatis不兼容的问题:An attempt was made to call a method that does not exist.

如何解决Mybatis-plus与Mybatis不兼容的问题

        在使用Mybatis-plus和Mybatis时,开发者可能会遇到版本不兼容的问题,这会导致应用程序无法正确运行。这类问题通常表现为方法不存在的错误,例如本文案例中的org.apache.ibatis.session.Configuration.setArgNameBasedConstructorAutoMapping(Z)V方法不存在。了解并解决这些问题对于保持项目的稳定性和可用性至关重要。

       报错信息如下

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2024-07-03 12:15:05.977 ERROR 20232 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: com.baomidou.mybatisplus.core.MybatisXMLScriptBuilder$ForEachHandler.handleNode(MybatisXMLScriptBuilder.java:230) The following method did not exist: org.apache.ibatis.scripting.xmltags.ForEachSqlNode.<init>(Lorg/apache/ibatis/session/Configuration;Lorg/apache/ibatis/scripting/xmltags/SqlNode;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V The calling method's class, com.baomidou.mybatisplus.core.MybatisXMLScriptBuilder$ForEachHandler, was loaded from the following location: jar:file:/D:/Maven_work/repository/com/baomidou/mybatis-plus-core/3.5.7/mybatis-plus-core-3.5.7.jar!/com/baomidou/mybatisplus/core/MybatisXMLScriptBuilder$ForEachHandler.class The called method's class, org.apache.ibatis.scripting.xmltags.ForEachSqlNode, is available from the following locations: jar:file:/D:/Maven_work/repository/org/mybatis/mybatis/3.5.7/mybatis-3.5.7.jar!/org/apache/ibatis/scripting/xmltags/ForEachSqlNode.class The called method's class hierarchy was loaded from the following locations: org.apache.ibatis.scripting.xmltags.ForEachSqlNode: file:/D:/Maven_work/repository/org/mybatis/mybatis/3.5.7/mybatis-3.5.7.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes com.baomidou.mybatisplus.core.MybatisXMLScriptBuilder$ForEachHandler and org.apache.ibatis.scripting.xmltags.ForEachSqlNode

这表明MybatisXMLConfigBuilder尝试调用一个在org.apache.ibatis.session.Configuration中不存在的方法。

解决这个问题有两种主要方法:降低Mybatis-plus的版本或升级Mybatis的版本。

降级Mybatis-plus版本
  1. 将Mybatis-plus的版本从3.5.2降级到3.5.1。

  2. 修改pom.xml文件中的依赖项,如下所示:

    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-core</artifactId>
        <version>3.5.1</version>
    </dependency>
    
  3. 重新构建项目以确保更改生效

小结

根据项目需求和其他依赖关系的兼容性,开发者可以选择降级Mybatis-plus或升级Mybatis。通常,保持依赖项的最新版本有助于利用最新的功能和修复。

 

  • 7
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值