异常描述
- 使用的SpringBoot1.5.9版本
- JDK1.8
- 使用了dubbo和zookeeper
详细报错信息:
1 | Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.NoSuchMethodError: org.jboss.netty.channel.socket.nio.NioWorker.<init>(Ljava/util/concurrent/Executor;Lorg/jboss/netty/util/ThreadNameDeterminer;)V |
异常分析
从异常的信息看,有两种可能:
- 没有netty包的原因
- 有多个netty包出现冲突
先找一下有没有netty包,找了一遍,发现有netty的
那只有第二种可能了,就是包冲入,又仔细看了一遍引入的JAR包,果然又出现了一个jar
然后挨个挨个查找,发现是dubbo和zookeeper里面已经有了netty包了,所以出现了包冲突。
解决办法
出错原因是Elasticsearch的netty包和dubbo、zookeeper里面的netty包冲突,我这里是排除了dubbo、zookeeper里面的netty包:
1 | <dependency> |
启动,成功!