这应该很容易;尝试以下操作:
/WEB-INF/web.xml 文件:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Your REST end Point</display-name>
<!-- /////////////////////// JERSEY (NO SPRING) ///////////////////////// -->
<servlet>
<servlet-name>MyRESTEndPoint</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<!- Package where jersey will scan for resources ->
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mycompany</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyRESTEndPoint</servlet-name>
<url-pattern>/MyRESTEndPoint/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
AT 包 com.mycompany(查看在 web.xml) 放置Application类:
package com.mycompany;
public class MyApp
extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(MyResource.class);
// ... add other resources
return s;
}
}
创建资源,如:
@Path("myResourcePath")
public class R01ERESTResourceForStructure {
@GET @Path("{myResourceId}")
@Produces(MediaType.APPLICATION_XML)
public Response load(@PathParam("myResourceId") final String id) {
....
}
}
您的网址应该是:像 /MyRESTEndPoint/myResourcePath/myResourceId
如果您使用的是 SPRING 或 GUICE,则 web.xml 应该有点不同