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

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

***************************
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分页拦截器有关
在这里插入图片描述
大概意思是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都给排除,如下

<dependency>
     <groupId>com.dycjr.xiakuan</groupId>
     <artifactId>xk-basic</artifactId>
     <version>1.0.0</version>
     <exclusions>
         <exclusion>
             <artifactId>jsqlparser</artifactId>
             <groupId>com.github.jsqlparser</groupId>
         </exclusion>
     </exclusions>
 </dependency>

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

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.<clinit>(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(<generated>)
	at com.dycjr.xiakuan.qh.config.MybatisPlusConfig$$EnhancerBySpringCGLIB$$3c78b384$$FastClassBySpringCGLIB$$221e8e89.invoke(<generated>)
	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(<generated>)
	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依赖,所以只能在外部再引入:

<!-- https://mvnrepository.com/artifact/com.github.jsqlparser/jsqlparser -->
 <dependency>
     <groupId>com.github.jsqlparser</groupId>
     <artifactId>jsqlparser</artifactId>
     <version>4.3</version>
 </dependency>

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

后续报错:
但在调用接口的时候,又发现出现了count()的错误,报错如下:
在这里插入图片描述

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

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

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

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

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

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值