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

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

码农世界 2024-06-05 后端 81 次浏览 0个评论

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

***************************
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依赖冲突可以看到

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/dafa7a009b3544a594bc5954568f5ff7.png

可以看到是项目中引入的另一个服务模块,依赖中的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解析器,引入不同的版本,导致冲突。

转载请注明来自码农世界,本文标题:《解决The following method did not exist:net.sf.jsqlparser.statement.select.SelectExpressionItem报错》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,81人围观)参与讨论

还没有评论,来说两句吧...

Top