dubbo的文件上传

我们这里使用hessian协议进行传输(当然也可以转换成byte[]继续使用dubbo协议)

下面是需要进行的配置

customer

需要引入hessian的包

<dependency>  
    <groupId>com.caucho</groupId>  
    <artifactId>hessian</artifactId>  
    <version>4.0.7</version>  
</dependency> 

provider

pom.xml 需要引入 hessian,jetty的包(Hessian底层采用Http通讯,采用Servlet暴露服务,Dubbo缺省内嵌Jetty作为服务器实现)

<dependency>  
    <groupId>com.caucho</groupId>  
    <artifactId>hessian</artifactId>  
    <version>4.0.7</version>  
</dependency>  
<dependency>  
    <groupId>org.mortbay.jetty</groupId>  
    <artifactId>jetty</artifactId>  
    <version>6.1.26</version>  
</dependency>  

provider.xml 需要配置hessian协议,并给service设置

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans    
  http://www.springframework.org/schema/beans/spring-beans.xsd    
  http://code.alibabatech.com/schema/dubbo  
  http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
    
    <!-- 提供方应用信息,用于计算依赖关系 -->  
    <dubbo:application name="provider" />  
  
    <!-- 使用zookeeper注册中心暴露服务地址 -->  
    <dubbo:registry address="zookeeper://127.0.0.1:2181" />  
      
    <!-- 监控中心 -->  
    <dubbo:monitor protocol="registry" />  
  
    <!-- 暴露服务 -->  
    <dubbo:protocol name="dubbo" port="20886" />  
    <dubbo:protocol name="hessian" port="20887"/>  
  
    <dubbo:service interface="com.dingcheng.user.facade.UserFacade" ref="userFacade" />  
  
    <!-- 需要指定hessian协议,否则会在上面设置的协议中随机调用,就会一会成功一会失败 -->  
    <dubbo:service protocol="hessian" interface="com.dingcheng.user.facade.UploadFacade" ref="uploadFacade" />  
</beans>  

其中 <dubbo:protocol name="hessian" port="20887"/> 就是默认的 server="jetty", 如果设置server="servlet",则需要web容器支持,我们的provider是以jar方式运行的,所以不适用这种.

 

 

转载于:https://my.oschina.net/LucasZhu/blog/1518261

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值