环境
代码地址dubbo-v2.6.x
- dubbo 2.6.5
- dubbo-spring-boot-starter 0.2.0
由于 dubbo-2.6.5 及以下版本的 Reference 还不支持 protocol 属性(dubbo-2.7.0支持了),注解暂时无法指定协议,但是可以使用xml配置指定协议
启动 provider 端
访问以下地址来判断provider
端使用多协议是否正常
http://localhost:9090/demo/echo?message=rest协议
启动 consumer 端
分别访问以下地址来判断consumer
端使用多协议是否正常
提示 AnnotationInjectedBeanPostProcessor 异常
issue1
Caused by: java.lang.ClassNotFoundException: com.alibaba.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor
解决,添加以下依赖1
2
3
4
5<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>1.0.2</version>
</dependency>
异常问题
- java.lang.NoClassDefFoundError: org/jboss/resteasy/client/jaxrs/engines/ApacheHttpClient4Engine
需要添加以下依赖包,该依赖 provider 端无需依赖,consumer 端需要依赖
1 | <dependency> |
- java.lang.RuntimeException: You must use at least one, but no more than one http method annotation on: top.ylonline.dubbo.spring.boot.example.api.EchoService.echo..
出现这个异常,说明要在使用的接口标注:@Path、@POST、@Get等javax.ws.rs.*这个路径下相关注解,不应该在实现类标注
1 | package top.ylonline.dubbo.spring.boot.example.api; |
dubbo-spring-boot-starter 中 spring-boot-starter scope 传递问题
1 | <dependency> |
由于dubbo-spring-boot-starter
中依赖了spring-boot-starter
的scope
是true
,会导致其继承spring-boot-starter-test
的scope
,使其变成test
1
2
3
4
5
6<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<scope>true</scope>
</dependency>
spring 版本不一致问题
项目中 pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<dubbo.version>2.6.5</dubbo.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-dependencies-bom</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>dubbo-dependencies-bom pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<properties>
<!-- Common libs -->
<spring_version>4.3.16.RELEASE</spring_version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Common libs -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring_version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
由于spring-boot-starter-parent
中的依赖的spring
版本是5.0.10
.RELEASE
,dubbo-dependencies-bom
中依赖了spring-framework-bom
,版本是4.3.16
.RELEASE
,会导致spring
的版本不一致问题
解决方法:将
dubbo-dependencies-bom
作为parent
,spring-boot-starter-parent
放到dependencyManagement
中,但是如果这样的话,有可能引发其他依赖问题