dubbo 集成restful协议

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/icoudsoft_saas/article/details/50394625

Maven工程请导入以下配置:


 
 
  1. <dependency>
  2. <groupId>javax.ws.rs </groupId>
  3. <artifactId>javax.ws.rs-api </artifactId>
  4. </dependency>

可忽略以下maven配置:


 
 
  1. <dependency>
  2. <groupId>org.jboss.resteasy </groupId>
  3. <artifactId>resteasy-jaxrs </artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.jboss.resteasy </groupId>
  7. <artifactId>resteasy-client </artifactId>
  8. </dependency>
  9. <dependency>
  10. <groupId>javax.el </groupId>
  11. <artifactId>javax.el-api </artifactId>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.glassfish.web </groupId>
  15. <artifactId>el-impl </artifactId>
  16. <scope>provided </scope>
  17. </dependency>
  18. <dependency>
  19. <groupId>org.apache.httpcomponents </groupId>
  20. <artifactId>httpcore </artifactId>
  21. </dependency>
1.spring-dubbo-service.xml 如下配置:tomcat


 
 
  1. <dubbo:protocol name="rest" port="8888" threads="500" contextpath="user" server="tomcat" accepts="500"
  2. extension= "com.alibaba.dubbo.rpc.protocol.rest.support.LoggingFilter"/>
<dubbo:service interface="com.sf.sgs.user.core.rest.service.CostomerRestService" ref="costomerRestServiceImpl" protocol="rest" document="customer"></dubbo:service>

 
 

2.定义接口:


 
 
  1. package com.sf.sgs.user.core.rest.service;
  2. import javax.ws.rs.Consumes;
  3. import javax.ws.rs.POST;
  4. import javax.ws.rs.Path;
  5. import javax.ws.rs.Produces;
  6. import javax.ws.rs.core.MediaType;
  7. @Path( "customer")
  8. @Produces({MediaType.APPLICATION_JSON + "; " + MediaType.CHARSET_PARAMETER + "=UTF-8", MediaType.TEXT_XML + "; " + MediaType.CHARSET_PARAMETER + "=UTF-8"})
  9. public interface CustomerServiceRest {
  10. @POST
  11. @Path( "test")
  12. @Consumes(MediaType.APPLICATION_JSON)
  13. String test(String name);
  14. }
3.访问:

访问URL:http://localhost:8888/user/customer/add

参数值:{"orgCode":"123ABC","source":1,"name":"leantaot","pinCode":"123456789123456","sex":"男","mobile":"110"}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值