[杂货铺系列]SpringBoot集成ElasticJob遇到的版本不兼容问题

背景

猿Why昨天在项目工程中引入ElasticJob的时候碰到一个异常:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-11-20 17:06:54.923 [] [main] ERROR [LoggingFailureAnalysisReporter.java:40] o.s.b.d.LoggingFailureAnalysisReporter - 

***************************
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:

    org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.registerServiceWatcher(ZookeeperServiceDiscovery.java:183)

The following method did not exist:

    org.apache.curator.framework.api.CreateBuilder.creatingParentsIfNeeded()Lorg/apache/curator/framework/api/ProtectACLCreateModeStatPathAndBytesable;

The method's class, org.apache.curator.framework.api.CreateBuilder, is available from the following locations:

    jar:file:/D:/maven_repo/org/apache/curator/curator-framework/2.10.0/curator-framework-2.10.0.jar!/org/apache/curator/framework/api/CreateBuilder.class

The class hierarchy was loaded from the following locations:

    org.apache.curator.framework.api.CreateBuilder: file:/D:/maven_repo/org/apache/curator/curator-framework/2.10.0/curator-framework-2.10.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.curator.framework.api.CreateBuilder

2022-11-20 17:06:55.666 [] [Curator-Framework-0] INFO  [CuratorFrameworkImpl.java:821] o.a.c.f.imps.CuratorFrameworkImpl - backgroundOperationsLoop exiting

项目中

springboot

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.3.1.RELEASEversion>
        <relativePath/> 
    parent>

dubbo

<dependency>
	<groupId>org.apache.dubbogroupId>
	<artifactId>dubbo-spring-boot-starterartifactId>
	<version>2.1.10version>
dependency>

elastic-job

<dependency>
	<groupId>com.dangdanggroupId>
 	<artifactId>elastic-job-lite-springartifactId>
	<version>2.1.5version>
dependency>

经过面向搜索引擎排查问题和Debug调试发现:
猿Why的代码中dubbo方面用到了org.apache.dubbo.config.annotation.DubboReference注解( @DubboReference)去调用Dubbo服务。

Spring容器在进行Bean初始化处理的时候,出现找不到方法的情况,于是抛出异常,导致程序无法启动。

也就是下面这一行异常信息反映的信息

org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.registerServiceWatcher(ZookeeperServiceDiscovery.java:183)

通过在dubbo的github社区,找到蛛丝马迹

    <groupId>com.alibaba.springgroupId>
    <artifactId>spring-context-supportartifactId>
    <version>1.0.10version>

以上jar的这个版本,在对 @DubboReference标注的Bean初始化的时候,对“zookeeper服务端和Client端版本不一致”的情况处理的不是太好。
所以需要对这个jar升级。

可以找到jar是在dubbo-spring-boot-starter的依赖中,经过尝试,找到解决办法:
需要将dubbo-spring-boot-starter升级到2.x的最高版本:2.7.18spring-context-support便会跟着升级到1.0.11

想到更多

目前可以搜索到的ElasticJob相关的文章多数是基于2.x系列的,zookeeper的版本小于3.5系列,curator在2.10.0。猿Why在这里记录一下可行的版本组合:

            
            <dependency>
                <groupId>org.apache.dubbogroupId>
                <artifactId>dubbo-spring-boot-starterartifactId>
                <version>2.7.18version>
            dependency>
        
        
        <dependency>
            <groupId>com.dangdanggroupId>
            <artifactId>elastic-job-lite-springartifactId>
            <version>2.1.5version>
        dependency>
            

如果遇到了找不到类、类中方法找不到等异常,大可进行jar排除,保留以上两个jar中的自有依赖。

另外,如果项目中不是像猿Why一样有历史包袱,大可以使用最新版本的组合(参考)。

你可能感兴趣的:(异常,Spring,spring,boot,dubbo,elasticjob)