springboot使用中,引入jar包冲突解决,通用方法

最核心的,看报错,仔细看控制台打印的输出日志。

下面以具体的案例来说明如何操作。先看报错:

*************************** 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: javax.el.ELManager.getExpressionFactory(ELManager.java:38) The following method did not exist: javax.el.ELUtil.getExpressionFactory()Ljavax/el/ExpressionFactory; The methods class, javax.el.ELUtil, is available from the following locations: jar:file:/C:/repo/mvn/tttt/javax/el/el-api/2.2/el-api-2.2.jar!/javax/el/ELUtil.class jar:file:/C:/repo/mvn/tttt/org/glassfish/jakarta.el/3.0.3/jakarta.el-3.0.3.jar!/javax/el/ELUtil.class The class hierarchy was loaded from the following locations: javax.el.ELUtil: file:/C:/repo/mvn/tttt/javax/el/el-api/2.2/el-api-2.2.jar

使用场景为,系统需要引入acitity7的工作流模块,和现有的hibernate相关的jar包冲突了。

在这些报错之后,还有很多异常抛出,找到其根源在:

Caused by: java.lang.NoSuchMethodError: javax.el.ELUtil.getExpressionFactory()Ljavax/el/ExpressionFactory

和开始的报错互相印证,可以知道原因在于 在el-api-2.2.jar和jakarta.el-3.0.3.jar中都有ELUtil这个类,系统真正使用的就是el-api-2.2.jar中的ELUtil.class类,而这个类中确没有需要的方法getExpressionFactory(),这个方法应该从jakarta.el-3.0.3.jar中引入。

那么该怎么办。

排除activity中引入的el-api-2.2.jar即可,在路径C:/repo/mvn/tttt/javax/el/el-api/2.2/el-api-2.2.jar中找到对应的pom文件配置:

<modelVersion>4.0.0</modelVersion> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> <packaging>jar</packaging> <version>2.2</version>

之后根据groupId和artifactId排除引入jar包:

报错解决。

其主要思路在于定位到冲突jar包,然后排除。不要盲目的根据错误去百度搜索,实际的情况千变万化,也很难搜到百分比契合自己问题的解决办法。

只有找出共性,以后遇到相同的问题,才可以一起迎刃而解。

经验分享 程序员 微信小程序 职场和发展