版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/icoudsoft_saas/article/details/50394625
Maven工程请导入以下配置:
-
<dependency>
-
<groupId>javax.ws.rs
</groupId>
-
<artifactId>javax.ws.rs-api
</artifactId>
-
</dependency>
可忽略以下maven配置:
-
<dependency>
-
<groupId>org.jboss.resteasy
</groupId>
-
<artifactId>resteasy-jaxrs
</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.jboss.resteasy
</groupId>
-
<artifactId>resteasy-client
</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>javax.el
</groupId>
-
<artifactId>javax.el-api
</artifactId>
-
</dependency>
-
<dependency>
-
<groupId>org.glassfish.web
</groupId>
-
<artifactId>el-impl
</artifactId>
-
<scope>provided
</scope>
-
</dependency>
-
<dependency>
-
<groupId>org.apache.httpcomponents
</groupId>
-
<artifactId>httpcore
</artifactId>
-
</dependency>
1.spring-dubbo-service.xml 如下配置:tomcat
-
<dubbo:protocol name="rest" port="8888" threads="500" contextpath="user" server="tomcat" accepts="500"
-
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.定义接口:
-
package com.sf.sgs.user.core.rest.service;
-
-
import javax.ws.rs.Consumes;
-
import javax.ws.rs.POST;
-
import javax.ws.rs.Path;
-
import javax.ws.rs.Produces;
-
import javax.ws.rs.core.MediaType;
-
-
@Path(
"customer")
-
@Produces({MediaType.APPLICATION_JSON +
"; " + MediaType.CHARSET_PARAMETER +
"=UTF-8", MediaType.TEXT_XML +
"; " + MediaType.CHARSET_PARAMETER +
"=UTF-8"})
-
public
interface CustomerServiceRest {
-
-
@POST
-
@Path(
"test")
-
@Consumes(MediaType.APPLICATION_JSON)
-
String test(String name);
-
}
3.访问:
访问URL:http://localhost:8888/user/customer/add
参数值:{"orgCode":"123ABC","source":1,"name":"leantaot","pinCode":"123456789123456","sex":"男","mobile":"110"}