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 */
JerseyService org.glassfish.jersey.servlet.ServletContainer jersey.config.server.provider.packages com.rest.resources javax.ws.rs.Application com.RestApplication 1 JerseyService /service/*