在web.xml中定义正确的资源路径?

时间:2013-02-19 17:49:58

标签: java rest tomcat jersey

我正在完成本教程:http://www.vogella.com/articles/REST/article.html#installation

我不明白它所说的“这个属性必须指向你的资源类。”这是从这一步:

5.3. Define Jersey Servlet dispatcher
You need to register Jersey as the servlet dispatcher for REST requests. Open the file web.xml and modify the file to the following.

<?xml version="1.0" encoding="UTF-8"?>
<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_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>de.vogella.jersey.first</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>de.vogella.jersey.first</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app> 
The parameter "com.sun.jersey.config.property.package" defines in which package jersey will look for the web service classes. This property must point to your resources classes. The URL pattern defines part of the base URL your application will be placed.

我已将球衣罐放入我的WEB-INF / lib文件夹中。那么我可以使用教程中提供的路径,还是应该使用其他东西?

1 个答案:

答案 0 :(得分:1)

他正在描述com.sun.jersey.config.property.package属性。这应该是包含项目中REST资源的包。这与将Jersey库添加到lib文件夹无关。他在本教程的第7.3节中介绍了这一点。只要您将REST类放在同一个包中,就可以保持原样。