springboot與dubbo的版本匹配
參考:
項(xiàng)目里原始版本
- springboot:2.1.6.RELEASE
- dubbo-spring-boot-starter : 0.2.1.RELEASE
- dubbo: 2.6.5
上面這么寫是可以正常運(yùn)行的。但是當(dāng)把dubbo升級(jí)到2.6.7時(shí)候,卻報(bào)錯(cuò)了,異常如下:
升級(jí)到2.6.7后錯(cuò)誤日志
Description:
The bean 'dubboConfigConfiguration.Single', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
后來經(jīng)過嘗試,把springboot的版本下調(diào)到2.0.9時(shí)候,項(xiàng)目可以正常啟動(dòng)。
所以得到下面這個(gè)版本匹配的結(jié)論:
2.7版本以下的,使用的是alibaba目錄下的jar,
springbootdubbo-springdubbo注1.x0.1.2.RELEASE2.6.5+2.6.6以上的dubbo需要配置netty-alljar包2.0.0~2.0.90.2.1.RELEASE2.6.5/2.6.6/2.6.72.1.x0.2.1.RELEASE2.6.5 /2.7.1
2.7版本以上的,用apache目錄下面的jar,dubbo-spring和dubbo都使用apache下面的版本,統(tǒng)一使用2.7即可,springboot也可以用2.1.x以上
springboot+dubbo版本對(duì)應(yīng)關(guān)系
背景
springboot 和 dubbo 在 pom.xml 中的版本是有對(duì)應(yīng)關(guān)系的,如果配置的依賴不按照對(duì)應(yīng)關(guān)系配置的話項(xiàng)目啟動(dòng)就會(huì)報(bào)錯(cuò),報(bào)錯(cuò)的信息如下所示:
java.lang.IllegalStateException: Cannot load configuration class: com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:249) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:283) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:127) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
at com.ProviderApplication.main(ProviderApplication.java:13) [classes/:na]
對(duì)應(yīng)關(guān)系
我在項(xiàng)目中使用的阿里巴巴的 dubbo-spring-boot-starter 版本是 0.2.0 ,maven 依賴如下所示:
1
2
3
4
5
|
< dependency > < groupId >com.alibaba.boot</ groupId > < artifactId >dubbo-spring-boot-starter</ artifactId > < version >0.2.0</ version > </ dependency > |
則對(duì)應(yīng)的使用 spring-boot-starter-parent 的版本號(hào)是 2.1.6.RELEASE ,這樣配置依賴的話,項(xiàng)目啟動(dòng)是沒有問題的。
Dubbo Spring Boot | Dubbo | Spring Boot |
0.2.1.RELEASE | 2.6.5+ | 2.x |
0.1.2.RELEASE | 2.6.5+ | 1.x |
可以在 https://mvnrepository.com/artifact/com.alibaba.boot/dubbo-spring-boot-starter 里面查看 dubbo 的所有版本信息。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/a718515028/article/details/98067864