问题描述
最近在做系统的架构升级,升级应用dubbo版本号至apache 2.7.18版,发生Caused by: java.lang.IllegalStateException: Failed to connect with zookeeper, pls check if url zookeeper://192.168.11.13:2149/ConfigCenterConfig?check=true&config-file=dubbo.properties&group=dubbo&highest-priority=false&timeout=3000 is correct.
错误。但这里奇怪的是,其他应用是没问题的。于是乎,将问题锁定在jar 包冲突上。
以下是详细错误信息。
错误信息
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxUserServiceImpl': Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to connect with zookeeper, pls check if url zookeeper://192.168.11.13:2181/ConfigCenterConfig?check=true&config-file=dubbo.properties&group=dubbo&highest-priority=false&timeout=3000 is correct.
at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:183)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1430)
at
…… org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:318)
... 49 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to connect with zookeeper, pls check if url zookeeper://192.168.11.13:2149/ConfigCenterConfig?check=true&config-file=dubbo.properties&group=dubbo&highest-priority=false&timeout=3000 is correct.
at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfiguration.<init>(ZookeeperDynamicConfiguration.java:69)
at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfigurationFactory.createDynamicConfiguration(ZookeeperDynamicConfigurationFactory.java:43)
at
……
com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:179)
... 65 common frames omitted
2023-03-27 18:59:41,758 INFO 3018 --- [ main] [org.apache.dubbo.spring.boot.context.event.WelcomeLogoApplicationListener:63] : [0]
:: Dubbo Spring Boot (v2.7.18) : https://github.com/apache/dubbo-spring-boot-project
:: Dubbo (v2.7.18) : https://github.com/apache/dubbo
:: Discuss group : dev@dubbo.apache.org
排查解决
1)打包启动正常的应用,解压打包后的springboot jar。查看其BOOT-INF目录下的lib。将依赖的lib 列表,复制其名称,写入good-libs.txt文件。
![在这里插入图片描述](https://img-blog.csdnimg.cn/d73b11116f8f4c7892ee5a5160294ad2.png)
2)同样的方法,打包启动失败的应用,查看其springboot 最终 lib 依赖包列表,复制其名称,写入bad-libs.txt文件。
3)比对bad-lib.txt 、good-lib.txt,寻找两个包依赖不同之处,重点关注dubbo、zookeeper、curator相关的包。
果然,经过一番对比,发现是curator-client 版本不一致。
![在这里插入图片描述](https://img-blog.csdnimg.cn/95acf9eddb00400eb39e553c0612ba3d.png)
4)查证 curator-client maven 依赖仲裁。
![在这里插入图片描述](https://img-blog.csdnimg.cn/caee8478cab54395bf14f4bd0b4d82f0.png)
原因是maven 发生依赖冲突时,最终采用了最短路径(路径只有2级,其他的版本都是3级路径),选择最底下的2.7.1版本。
现在只需要让2.10.0的版本被采纳就行了。
解决方法
1)方法一:直接声明curator-client坐标,让其优先级最高
<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)方法二:排除 curator-client 2.7.1 的依赖。在引入2.7.1版本的地方,exclusion掉依赖即可。
<exclusion>
<artifactId>curator-client</artifactId>
<groupId>org.apache.curator</groupId>
</exclusion>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)