• [杂货铺系列]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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    项目中

    springboot

        <parent>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-parentartifactId>
            <version>2.3.1.RELEASEversion>
            <relativePath/> 
        parent>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    dubbo

    <dependency>
    	<groupId>org.apache.dubbogroupId>
    	<artifactId>dubbo-spring-boot-starterartifactId>
    	<version>2.1.10version>
    dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    elastic-job

    <dependency>
    	<groupId>com.dangdanggroupId>
     	<artifactId>elastic-job-lite-springartifactId>
    	<version>2.1.5version>
    dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

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

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

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

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

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

        <groupId>com.alibaba.springgroupId>
        <artifactId>spring-context-supportartifactId>
        <version>1.0.10version>
    
    • 1
    • 2
    • 3

    以上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>
                
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

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

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

  • 相关阅读:
    为什么都说测试岗是巨坑,趁早跳出去?10年测试人告诉你千万别上当了...
    【VIO】第1讲 IMU 传感器
    ORM--查询类型,关联查询
    计算机毕业设计Java电子存证系统(源码+系统+mysql数据库+lw文档)
    JavaScript和Java的区别是什么?
    想进入社交电商,但却害怕投入回本无望?来试一试这样做
    随缘记录一些MySQL问题
    JSP JavaBean的使用
    39.JS插件
    计算机领域期刊会议级别分类
  • 原文地址:https://blog.csdn.net/u010730731/article/details/127951211