记一次jar冲突的问题

问题

业务中需要在spark中链接redis作为服务缓存,spark程序中引入redis的jar包后上传spark集群运行是报java.lang.NoSuchMethodError: com.xxx.common.pool.ConnectionPool.startAsync()Lcom/google/common/util/concurrent/Service;根据报错信息发现是jar包冲突造成

解决方式

  1. 根据报错信息判断是com/google/common/util这个包造成的冲突,在idea的external中找到该包的maven坐标应该是com.google.guava:guava:18.0
  2. 然后在idea的Dependency Analyzer中搜索guava发现生效的包和redis包中的版本相同,所以冲突应该不是本地项目造成的
  3. 然后有将jar上传tce运行,发现没有问题。因此定位问题应该是本地项目的com.google.guava依赖和spark集群中的依赖冲突造成
  4. 通过maven的shade插件将com.google.guava重命名后解决jar包冲突问题
xml 复制代码
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.1</version>
    <executions>
    	<execution>
    		<phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
            	<minimizeJar>false</minimizeJar>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <relocations>
                   <relocation>
                       <pattern>com.google.common</pattern>
                       <shadedPattern>shade.com.google.common</shadedPattern>
                   </relocation>
                </relocations>
                <filters>
                	<filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
    	</execution>
    </executions>
</plugin>
相关推荐
南梦浅9 分钟前
网站redis从开发到部署方案
java·jvm·redis
阿kun要赚马内12 分钟前
操作系统:线程与进程
java·开发语言·jvm
pupudawang15 分钟前
如何查询SQL Server数据库服务器的IP地址
java
SimonKing15 分钟前
IntelliJ IDEA 配置与插件全部迁移到其他盘,彻底释放C盘空间
java·后端·程序员
华科易迅18 分钟前
Spring 代理
java·后端·spring
我真会写代码20 分钟前
深度解析ConcurrentHashMap:从底层原理到生产实战,搞定并发安全映射(含面试避坑)
java·并发编程
liangdabiao23 分钟前
XHS_Business_Idea_Validator-小红书解析市场机会智能体
java·ide·intellij-idea
xnian_29 分钟前
高并发下锁管理器,单机与分布式版
java·开发语言
凌波粒33 分钟前
LeetCode--203.移除链表元素(链表)
java·算法·leetcode·链表
程序员buddha36 分钟前
Java面试八股文基础篇
java·开发语言·面试