dubbo 2.7.0 中缺乏 <dubbo:annotation /> 的解决方案

一、背景

 从 dubbo 2.6.5 升级到 2.7.0,突然发现好多地方不能用了,dubbo:annotation 直接报红,原先的 @Service 和 @Reference 中直接报了过时,源码里面也没有告知替代的类,真是耍流氓。。

二、dubbo 2.7.0 介绍

 Dubbo 2.7.0 添加了异步化支持。异步化支持不再局限于基于 Future 接口的异步,也不再仅仅局限于只能在客户端异步。具体来说,Dubbo 2.7.0 版本全面拥抱 JDK8,在客户端开始支持基于 CompletableFuture 的异步编程范式,在服务端支持基于 AsyncContext 的异步模型。

 Dubbo 2.7.0 中,通过对 URL 的改造,将注册中心拆分成了三个中心,分别是注册中心、配置中心和元数据中心,三者各司其责,不仅有效地解决了上述容量问题,而且很好地适应了微服务的技术架构,用户可以开始自由选择适合自己场景的注册中心和配置中心。

 Dubbo 2.7.0 版本在改造的过程中遵循了一个原则,即保持与低版本的兼容性,因此从功能层面来说它是与2.6.x及更低版本完全兼容的。

 官方 Dubbo 2.7.0 的说明文档:http://dubbo.incubator.apache.org/zh-cn/docs/user/versions/version-270.html

三、解决方案

  1. @Service 和 @Reference 中过时:Package重命名 com.alibaba.dubbo -> org.apache.dubbo
  2. dubbo:annotation 失效:改掉xml 的命名空间
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <!-- dubbo 配置 -->
    <dubbo:application name="ts_provider_common"/>
    <dubbo:registry address="${zookeeper.host}" simplified="true"/>
    <dubbo:protocol name="dubbo" port="-1"/>
    <dubbo:provider timeout="3000" retries="0"/>
    <dubbo:consumer check="false"/>
    <dubbo:annotation package="com.demo"/>
</beans>
posted @ 2019-03-13 17:42  JMCui  阅读(5919)  评论(2编辑  收藏  举报