记一次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>
相关推荐
麦兜*44 分钟前
Spring Boot 企业级动态权限全栈深度解决方案,设计思路,代码分析
java·spring boot·后端·spring·spring cloud·性能优化·springcloud
ruan1145142 小时前
MySQL4种隔离级别
java·开发语言·mysql
Hellyc6 小时前
基于模板设计模式开发优惠券推送功能以及对过期优惠卷进行定时清理
java·数据库·设计模式·rocketmq
lifallen6 小时前
Paimon LSM Tree Compaction 策略
java·大数据·数据结构·数据库·算法·lsm-tree
hdsoft_huge6 小时前
SpringBoot 与 JPA 整合全解析:架构优势、应用场景、集成指南与最佳实践
java·spring boot·架构
百锦再7 小时前
详细解析 .NET 依赖注入的三种生命周期模式
java·开发语言·.net·di·注入·模式·依赖
程序员的世界你不懂7 小时前
基于Java+Maven+Testng+Selenium+Log4j+Allure+Jenkins搭建一个WebUI自动化框架(2)对框架加入业务逻辑层
java·selenium·maven
有没有没有重复的名字8 小时前
线程安全的单例模式与读者写者问题
java·开发语言·单例模式
程序员的世界你不懂9 小时前
基于Java+Maven+Testng+Selenium+Log4j+Allure+Jenkins搭建一个WebUI自动化框架(4)集成Allure报表
java·selenium·maven
isNotNullX10 小时前
数据中台架构解析:湖仓一体的实战设计
java·大数据·数据库·架构·spark