解决The following method did not exist:net.sf.jsqlparser.statement.select.SelectExpressionItem报错

2024-07-21 1153阅读

最近在启动一个新的项目的时候,遇到了以下报错:

***************************
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.extension.plugins.inner.PaginationInnerInterceptor.defaultCountSelectItem(PaginationInnerInterceptor.java:79)
The following method did not exist:
    net.sf.jsqlparser.statement.select.SelectExpressionItem.withAlias(Lnet/sf/jsqlparser/expression/Alias;)Lnet/sf/jsqlparser/statement/select/SelectExpressionItem;
The method's class, net.sf.jsqlparser.statement.select.SelectExpressionItem, is available from the following locations:
    jar:file:/D:/SoftWare/dev/maven/apache-maven-3.6.3/repository/com/github/jsqlparser/jsqlparser/3.2/jsqlparser-3.2.jar!/net/sf/jsqlparser/statement/select/SelectExpressionItem.class
The class hierarchy was loaded from the following locations:
    net.sf.jsqlparser.statement.select.SelectExpressionItem: file:/D:/SoftWare/dev/maven/apache-maven-3.6.3/repository/com/github/jsqlparser/jsqlparser/3.2/jsqlparser-3.2.jar
    net.sf.jsqlparser.parser.ASTNodeAccessImpl: file:/D:/SoftWare/dev/maven/apache-maven-3.6.3/repository/com/github/jsqlparser/jsqlparser/3.2/jsqlparser-3.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of net.sf.jsqlparser.statement.select.SelectExpressionItem

查了一下,是mybatis-plus的版本冲突问题,但到底是哪里的冲突呢?从报错具体信息上看与mybatisplus分页拦截器有关

解决The following method did not exist:net.sf.jsqlparser.statement.select.SelectExpressionItem报错

大概意思是jsqlparser包冲突了,但是哪两个依赖里面的jsqlparser呢?一个报错是从com/github/jsqlparser路径加载的,右键分析了下maven依赖冲突可以看到

解决The following method did not exist:net.sf.jsqlparser.statement.select.SelectExpressionItem报错

可以看到是项目中引入的另一个服务模块,依赖中的mybatis-plus-extension中jsqlparser与pagehelper中的jsqlparser冲突引起的

于是,我使用了Maven-Helper工具,将mybatis-plus-extension与pagehelper中的jsqlparser都给排除,如下

     com.dycjr.xiakuan
     xk-basic
     1.0.0
     
         
             jsqlparser
             com.github.jsqlparser
         
     
 

但项目启动,又报了新的错误:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor]: Factory method 'mybatisPlusInterceptor' threw exception; nested exception is java.lang.NoClassDefFoundError: net/sf/jsqlparser/expression/Function
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:652)
	... 96 common frames omitted
Caused by: java.lang.NoClassDefFoundError: net/sf/jsqlparser/expression/Function
	at com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor.defaultCountSelectItem(PaginationInnerInterceptor.java:76)
	at com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor.(PaginationInnerInterceptor.java:68)
	at com.dycjr.xiakuan.qh.config.MybatisPlusConfig.mybatisPlusInterceptor(MybatisPlusConfig.java:24)
	at com.dycjr.xiakuan.qh.config.MybatisPlusConfig$$EnhancerBySpringCGLIB$$3c78b384.CGLIB$mybatisPlusInterceptor$0()
	at com.dycjr.xiakuan.qh.config.MybatisPlusConfig$$EnhancerBySpringCGLIB$$3c78b384$$FastClassBySpringCGLIB$$221e8e89.invoke()
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at com.dycjr.xiakuan.qh.config.MybatisPlusConfig$$EnhancerBySpringCGLIB$$3c78b384.mybatisPlusInterceptor()
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 97 common frames omitted
Caused by: java.lang.ClassNotFoundException: net.sf.jsqlparser.expression.Function
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:359)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 110 common frames omitted

从服务报错看起来,又缺少了jsqlparser的依赖😂,原来项目用到了MybatisPlusInterceptor分页拦截器,会引用到jsqlparser依赖,所以只能在外部再引入:

 
     com.github.jsqlparser
     jsqlparser
     4.3
 

ok,添加完之后,项目顺利启动

后续报错:

但在调用接口的时候,又发现出现了count()的错误,报错如下:

解决The following method did not exist:net.sf.jsqlparser.statement.select.SelectExpressionItem报错

原因分析:项目中用到的mybatis-plus版本为3.3.1与引入的jsqlparser4.3版本不对应

     com.baomidou
      mybatis-plus-boot-starter
      3.3.1
  

解决方案:升级mybatis-plus版本

     com.baomidou
     mybatis-plus-boot-starter
     3.5.3.1
 
 
     com.baomidou
     mybatis-plus-extension
     3.5.3.1
 

总结:原本以为是mybatis-plus版本导致的,结果改了几次版本号之后,依然没有用,所以只好从报错日志分析,其实是项目用到了pagehelper与mybatis-plus,两者都用到了jsqlparser作为sql解析器,引入不同的版本,导致冲突。

VPS购买请点击我

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

目录[+]