记一次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>
相关推荐
敖正炀4 分钟前
BlockingQueue 与生产者-消费者模式:并发数据传递的源码内核
java
敖正炀5 分钟前
Stream API 惰性求值与内部迭代
java
日月云棠5 分钟前
4 高级配置:容错策略、降级保护与流量控制
java·后端
人道领域9 分钟前
Java基础热门八股总结:八种基本数据类型 + 装箱拆箱 + 缓存机制,(90%的Java新手都搞不清的装箱拆箱问题)
java·开发语言·python
jameslogo9 分钟前
如何用RocketMQTemplate发送事务消息
java·spring boot·rocketmq
菜鸟小九19 分钟前
JUC补充(ThreadLocal、completableFuture)
java·开发语言
Seven971 小时前
两小时入门Sentinel
java
tongluowan0071 小时前
Java中atomic底层原理 - ABA 问题与解决方案
java·juc·atomic
无关86881 小时前
Spring Boot 项目标准化部署打包实战
java·spring boot·后端
jay神2 小时前
基于微信小程序课外创新实践学分认定系统
java·spring boot·小程序·vue·毕业设计