项目接入elastic-job作为调度中心的各种依赖问题

项目之前是使用的spring注解

@Scheduled

的方式完成定时任务,但是对于需要经常改corn的项目来说,并且期望是更加灵活地分布式的场景,就显得捉襟见肘,于是乎,在xxl-job,自建qurtz集群,elastic等组件里,项目引入了elastic-job。

但是在接入的过程中项目一直启动不了,下面记录下过程中出现的依赖问题

报错1:提示CreateBuilder.creatingParentsIfNeeded方法不存在

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter.persistEphemeral(ZookeeperRegistryCenter.java:246)

The following method did not exist:

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

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

    jar:file:/Users/admin/.m2/repository/org/apache/curator/curator-framework/4.2.0/curator-framework-4.2.0.jar!/org/apache/curator/framework/api/CreateBuilder.class

It was loaded from the following location:

    file:/Users/admin/.m2/repository/org/apache/curator/curator-framework/4.2.0/curator-framework-4.2.0.jar

Action:

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

对比curator版本之后,发现早期版本是有这个方法的,所以对curator相关包降版本为2.10.0:

<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-framework</artifactId>
    <version>2.10.0</version>
</dependency>
<dependency> 
<groupId>org.apache.curator</groupId> 
<artifactId>curator-recipes</artifactId>
 <version>2.10.0</version>
</dependency>

<dependency> 
<groupId>org.apache.curator</groupId> 
<artifactId>curator-client</artifactId> 
<version>2.10.0</version>
</dependency>

接着出现下面的依赖错误:

报错2:22.0版本guava报错

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.apache.curator.framework.listen.ListenerContainer.addListener(ListenerContainer.java:41)

The following method did not exist:

com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;

The method's class, com.google.common.util.concurrent.MoreExecutors, is available from the following locations:

    jar:file:/Users/admin/.m2/repository/com/google/guava/guava/22.0/guava-22.0.jar!/com/google/common/util/concurrent/MoreExecutors.class

It was loaded from the following location:

    file:/Users/admin/.m2/repository/com/google/guava/guava/22.0/guava-22.0.jar

提示不存在MoreExecutors.sameThreadExecutor包,于是对guava包降版本为18.0

报错3:18.0版本guava版本报错

Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V

at com.google.inject.TypeLiteral.getParameterTypes(TypeLiteral.java:278)

at com.google.inject.spi.InjectionPoint.forMember(InjectionPoint.java:136)

at com.google.inject.spi.InjectionPoint.<init>(InjectionPoint.java:95)

at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:334)

at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:117)

at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:716)

at com.google.inject.internal.UntargettedBindingProcessor$1.visit(UntargettedBindingProcessor.java:54)

at com.google.inject.internal.UntargettedBindingProcessor$1.visit(UntargettedBindingProcessor.java:36)

at com.google.inject.internal.UntargettedBindingImpl.acceptTargetVisitor(UntargettedBindingImpl.java:52)

at com.google.inject.internal.UntargettedBindingProcessor.visit(UntargettedBindingProcessor.java:35)

at com.google.inject.internal.UntargettedBindingProcessor.visit(UntargettedBindingProcessor.java:27)

at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:99)

at com.google.inject.internal.AbstractProcessor.lambda$process$0(AbstractProcessor.java:53)

at java.util.ArrayList.removeIf(ArrayList.java:1415)

at com.google.inject.internal.AbstractProcessor.process(AbstractProcessor.java:50)

at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:216)

at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)

at com.google.inject.Guice.createInjector(Guice.java:87)

at com.google.inject.Guice.createInjector(Guice.java:69)

at com.google.inject.Guice.createInjector(Guice.java:59)

at com.ctrip.framework.apollo.spring.util.SpringInjector.getInjector(SpringInjector.java:38)

... 15 more

于是找到中间版本20.0,终于解决

还有curator相应包中需要排除掉zookeeper依赖(curator和zookeeper也有冲突),和guava依赖

<dependency>
    <groupId>org.apache.curator</groupId>
    <artifactId>curator-framework</artifactId>
    <version>2.10.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </exclusion>
        <exclusion>
            <artifactId>guava</artifactId>
            <groupId>com.google.guava</groupId>
        </exclusion>
    </exclusions>
</dependency>

引入zookeeper包

<dependency>
        <groupId>org.apache.zookeeper</groupId>
        <artifactId>parent</artifactId>
        <version>3.5.8</version>
</dependency>

上面的包依赖冲突,一层套一层,花了一天时间才解决,经验就是在解决包依赖冲突时,使用控制变量法,fix一个问题,并确定没问题之后,再注意解决后面的,多个一起改的话,很容易改懵了!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值