dubbo中间件的rest协议踩过的坑

一、所需jar包如下
<!--  dubbo 开始 -->
            < dependency >
              < groupId >com.alibaba </ groupId >
              < artifactId >dubbo </ artifactId >
              < version >2.6.0 </ version >
              < exclusions >
                 < exclusion >
                     < groupId >log4j </ groupId >
                     < artifactId >log4j </ artifactId >
                 </ exclusion >
             </ exclusions >
            </ dependency >
            < dependency >
             < groupId >org.apache.zookeeper </ groupId >
             < artifactId >zookeeper </ artifactId >
             < version >3.4.6 </ version >
         </ dependency >
            < dependency >
          < groupId >com.101tec </ groupId >
          < artifactId >zkclient </ artifactId >
           < version >0.7 </ version >
            </ dependency >
            <!--  dubbo 结束 -->
二 、配置成servlet方式,与web项目共用容器,contextpath为容器下war路径
<? xml  version= "1.0"  encoding= "UTF-8" ?>
        xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
        xmlns:dubbo= "http://code.alibabatech.com/schema/dubbo"
        xmlns:context= "http://www.springframework.org/schema/context"
     < dubbo:application  name= "ft-billapplication"  logger= "slf4j" />
     <dubbo:registry address=" zookeeper://127.0.0.1:2181" timeout="3000" />
     < dubbo:protocol  name= "dubbo"  port= "20880" />
     < dubbo:protocol  name= "rest"  port= "8088"  contextpath= "ft-my"  server= "servlet" />
     < dubbo:service  interface= "io.my.ft.bill.api.CreditCardStatementApi"    ref= "creditStatementApi"  />
     < dubbo:service  interface= "io.my.ft.bill.api.CreditCardStatementQueryApi"   ref= "creditStatementQueryApi"  />
</ beans >
2.1  web.xml配置

       需要添加dubbo的listener与servlet,注意不要与spring mvc冲突,保证dubbo的listener与servlet优先于spring mvc加载!!!

       dubbo依赖如下:

    < listener >
         < listener-class >com.alibaba.dubbo.remoting.http.servlet.BootstrapListener </ listener-class >
     </ listener >
      < servlet >
            < servlet-name >dubboDispatcher </ servlet-name >
           < servlet-class >com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet </ servlet-class >
            < load-on-startup >1 </ load-on-startup >
      </ servlet >
      < servlet-mapping >
          < servlet-name >dubboDispatcher </ servlet-name >
          < url-pattern >/* </ url-pattern >
      </ servlet-mapping >
    随后的spring mvc配置如下:
    < listener >
           < listener-class >org.springframework.web.context.ContextLoaderListener </ listener-class >
      </ listener >
      < servlet >
            < servlet-name >spring </ servlet-name >
           < servlet-class >org.springframework.web.servlet.DispatcherServlet </ servlet-class >
            < init- param >
                 < param-name >contextConfigLocation </ param-name >
                 < param-value > classpath*: biz/spring-mvc.xml </ param-value >
            </ init- param >
            < load-on-startup >1 </ load-on-startup >
      </ servlet >
      < servlet-mapping >
            < servlet-name >spring </ servlet-name >
             < url-pattern >/clear/gen </ url-pattern >
           <url-pattern>/ok.htm</url-pattern>
      </ servlet-mapping >

2.2 配置成servlet形式优点:与项目共用一个容器进程,缺点是:原项目中spring mvc的Controller层的http接口地址,静态资源需要在web.xml中一一列出在<url-pattern>/clear/gen</url-pattern>

三、配置成非servlet方式,dubbo的rest接口单独启动一套容器进程,与项目的web容器互不影响,与spring mvc没冲突

<? xml  version= "1.0"  encoding= "UTF-8" ?>
        xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
        xmlns:dubbo= "http://code.alibabatech.com/schema/dubbo"
        xmlns:context= "http://www.springframework.org/schema/context"
     < dubbo:application  name= "ft-billapplication"  logger= "slf4j" />
     <dubbo:registry address=" zookeeper://127.0.0.1:2181" timeout="3000" />
     < dubbo:protocol  name= "dubbo"  port= "20880" />
     < dubbo:protocol  name= "rest"  port= "8088"  />
     < dubbo:service  interface= "io.my.ft.bill.api.CreditCardStatementApi"    ref= "creditStatementApi"  />
     < dubbo:service  interface= "io.my.ft.bill.api.CreditCardStatementQueryApi"   ref= "creditStatementQueryApi"  />
</ beans >
web.xml配置不必修改,不需要添加dubbo的listener与servlet

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值