Dubbo 2.6.x使用

环境

代码地址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 异常

issue

1
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
2
3
4
5
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy-client.version}</version>
</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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package top.ylonline.dubbo.spring.boot.example.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

/**
* @author YL
*/
@Path("/demo")
public interface EchoService {
/**
* echo
*
* @param message msg
*
* @return 信息
*/
@GET
@Path("/echo")
String echo(@QueryParam("message") String message);
}

dubbo-spring-boot-starter 中 spring-boot-starter scope 传递问题

1
2
3
4
5
6
7
8
9
10
11
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>

由于dubbo-spring-boot-starter中依赖了spring-boot-starterscopetrue,会导致其继承spring-boot-starter-testscope,使其变成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 .RELEASEdubbo-dependencies-bom中依赖了spring-framework-bom,版本是4.3.16 .RELEASE,会导致spring的版本不一致问题

解决方法:将dubbo-dependencies-bom作为parentspring-boot-starter-parent放到dependencyManagement中,但是如果这样的话,有可能引发其他依赖问题

  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/61ed87a1.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!