项目之前是使用的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一个问题,并确定没问题之后,再注意解决后面的,多个一起改的话,很容易改懵了!