简体   繁体   中英

Why do I get a 404 on this REST tutorial?

I've been following along on this REST tutorial here: http://www.vogella.com/tutorials/REST/article.html

I've worked with REST before but not from the ground up and not using Tomcat, so I thought I'd start from the beginning and go from thee. Thing is I'm just getting a 404 when it comes to step 6.4 on this tutorial.

My web.xml looks like this:

<?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>

And the resource seems to be getting detected by Tomcat upon startup:

09/08/2014 9:35:47 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
09/08/2014 9:35:47 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:RAGRest' did not find a matching property.
09/08/2014 9:35:47 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
09/08/2014 9:35:47 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 337 ms
09/08/2014 9:35:47 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
09/08/2014 9:35:47 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.41
09/08/2014 9:35:47 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  de.vogella.jersey.first
09/08/2014 9:35:47 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class de.vogella.jersey.first.Hello
09/08/2014 9:35:47 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
09/08/2014 9:35:47 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.18 11/22/2013 01:21 AM'
09/08/2014 9:35:48 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
09/08/2014 9:35:48 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
09/08/2014 9:35:48 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/9  config=null
09/08/2014 9:35:48 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 956 ms

And tomcat is up and running at localhost:8080 as proved by visiting it in the browser. Yet when I hit http://localhost:8080/de.vogella.jersey.first/rest/hello all I get is a 404.

Am I missing something that is just blatantly obvious? I must be...

In case it matters, this is running tomcat 6 in Eclipse Helios on a MacBook Pro.

The URL part "de.vogella.jersey.first" needs to be the name of your WAR deployment unit (or web container specific methods like jboss-web.xml or Tomcat context.xml ).

At least for normal web-apps this is the case, don't know why the tutorial speaks about the display-name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM