目录
1.起因
最近在若依框架内引入了Mybatis Plus 3.5.6,在IEDA运行时可以正常运行,但是jar包运行时报错,报错信息如下,可以看到关键信息为nested exception is java.lang.NoClassDefFoundError: net/sf/jsqlparser/statement/select/SelectBody
19:36:34.464 [main] ERROR o.s.b.SpringApplication - [reportFailure,870] - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/sf/jsqlparser/statement/select/SelectBody
观察可以看到是com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration的配置文件报错,而PageHelper是集成在MybatisPlus中的,但这个现象很奇怪,在IEDA运行下无报错信息,但是jar运行时却提示无法加载net/sf/jsqlparser/statement/select/SelectBody的bean对象,在Maven仓库检索后发现,这个依赖在2012年已转移到com.github
2.解决方案
查阅资料和试错情况下,发现是IEDA的运行时可以正常检索到com.github.jsqlparser的包依赖路径,但是在打包jar运行的情况下,默认的包路径居然是net.sf.jsqlparser路径,推测是IEDA的运行机制和jar运行的差异化导致的路径异常问题。在后续的实验中,发现有两种解决方案
2.1.导入缺少的net.sf.jsqlparser包
<dependency>
<groupId>net.sf.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>0.8.0</version>
</dependency>
2.2.使用高版本的Mybatis Plus
<!--mybatis plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.5.9</version>
</dependency>