Jas*_*len 26 eclipse rest servlets jersey
我已经阅读了很多帖子,但似乎无法解决我的问题.你也会看到很多帖子与这个帖子非常相似,甚至是同一个教程.即便跟着他们,我似乎无法得到答案.
基本上,我正在尝试遵循以下简单教程:http://www.vogella.com/articles/REST/
我做了一些修改,使其与Jersey 2.x兼容
我正在使用:Eclipse Tomcat 6(在Eclipse中部署/运行)jaxrs-ri-2.0我在Eclipse中启用了JAX-RS Facet
一切都很好构建Tomcat在Eclipse中开始很好我可以通过以下方式获取静态页面内容:
http://localhost:8080/RestTEST2/index.html
但是,当我尝试通过以下方式访问我的服务时:
http://localhost:8080/RestTEST2/jaxrs/hello 
我收到404"未找到消息"和"请求的资源(未找到)不可用."
这是我的web.xml,位于/WebContent/WEB-INF/web.xml
<?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" 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>TestREST2</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
  <description>JAX-RS Tools Generated - Do not modify</description>
  <servlet-name>JAX-RS Servlet</servlet-name>
  <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>TestREST</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>  
  </servlet>
    <servlet-mapping>
      <servlet-name>JAX-RS Servlet</servlet-name>
      <url-pattern>/jaxrs/*</url-pattern>
    </servlet-mapping>
</web-app>
这是我的Java类:
package TestREST;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
// Plain old Java Object it does not extend as class or implements 
// an interface
// The class registers its methods for the HTTP GET request using the @GET annotation. 
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML. 
// The browser requests per default the HTML MIME type.
//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {
  // This method is called if TEXT_PLAIN is request
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayPlainTextHello() {
    return "Hello Jersey";
  }
  // This method is called if XML is request
  @GET
  @Produces(MediaType.TEXT_XML)
  public String sayXMLHello() {
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
  }
  // This method is called if HTML is request
  @GET
  @Produces(MediaType.TEXT_HTML)
  public String sayHtmlHello() {
    return "<html> " + "<title>" + "Hello Jersey" + "</title>"
        + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
  }   
} 
我还配置并引用了一个包含所有JAX-RS jar的JAX-RS用户库.
关于什么会导致无法找到Web服务的想法?
Mic*_*dos 26
Jersey 2.0无法识别名称为init-param com.sun.jersey.config.property.packages(web.xml).尝试将其更改jersey.config.server.provider.packages为ServerProperties.PROVIDER_PACKAGES中所述.
非常感谢..我也一直为此而奋斗。
这种组合对我有用:Tomcat 7.0.55 Eclipse Luna Java 1.6 Jersey 1.7
web.xml:
<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.trgr.cobalt.cmdb.jersey.resource;com.trgr.cobalt.cmdb.jersey.beans;com.trgr.cobalt.cmdb.elasticity</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>
| 归档时间: | 
 | 
| 查看次数: | 47277 次 | 
| 最近记录: |