记一次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>
相关推荐
消失的旧时光-19432 分钟前
第四篇(实战): 订单表索引设计实战:从慢 SQL 到毫秒级
java·数据库·sql
それども23 分钟前
@ModelAttribute vs @RequestBody
java
雨中飘荡的记忆1 小时前
深度详解Spring Context
java·spring
Tao____1 小时前
JAVA开源物联网平台
java·物联网·mqtt·开源·ruoyi
yqd6661 小时前
SpringSecurity的使用
java·spring
仙俊红1 小时前
Java Map 家族核心解析
java·开发语言
一嘴一个橘子2 小时前
springMvc 接收参数、cookie、header
java
code_li3 小时前
聊聊支付宝架构
java·开发语言·架构
CC.GG3 小时前
【Linux】进程概念(五)(虚拟地址空间----建立宏观认知)
java·linux·运维
以太浮标4 小时前
华为eNSP模拟器综合实验之- AC+AP无线网络调优与高密场景
java·服务器·华为