标签:内容 resource etc rest ati ping containe -name value
package com.rest.resources; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; /**
* 接口内容类
*/
@Path("/test") public class Test { @GET @Path("/1") @Produces(MediaType.TEXT_PLAIN) public String test1() { return "laoliudashabi"; } }
1 package com; 2 3 import org.glassfish.jersey.server.ResourceConfig; 4
/**
* 接口注册类
*/
5 public class RestApplication extends ResourceConfig{ 6 public RestApplication() { 7 //声明资源包所在位置 8 packages("com.rest.resources"); 9 10 } 11 }
/**
* web.xml
*/
<servlet> <servlet-name>JerseyService</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <!--接口包名--> <param-value>com.rest.resources</param-value> </init-param> <init-param> <param-name>javax.ws.rs.Application</param-name> <!--注册类--> <param-value>com.RestApplication</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>JerseyService</servlet-name> <!--访问路径--> <url-pattern>/service/*</url-pattern> </servlet-mapping>
标签:内容 resource etc rest ati ping containe -name value
原文地址:http://www.cnblogs.com/lxnv587/p/7967056.html