jersey 接口發布
阿新 • • 發佈:2017-12-03
ping class nta pla res org abi tar 訪問路徑
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>
jersey 接口發布