我一直在关注此REST教程:http://www.vogella.com/tutorials/REST/article.html
我之前曾与REST合作,但不是从头开始使用Tomcat,所以我想我从一开始就从你那里开始。在本教程的第6.4步中,我只是得到了404。
我的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" 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>
Tomcat在启动时似乎正在检测资源:
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
tomcat已启动并运行在localhost:8080,通过在浏览器中访问它证明了这一点。然而,当我点击http://localhost:8080/de.vogella.jersey.first/rest/hello
时,我得到的只是404。
我错过了一些显而易见的东西吗?我一定是......
如果重要,这是在MacBook Pro上的Eclipse Helios中运行tomcat 6。
答案 0 :(得分:2)
网址部分&#34; de.vogella.jersey.first&#34;需要是WAR部署单元的名称(或特定于Web容器的方法,如jboss-web.xml
或Tomcat context.xml
)。
至少对于普通的网络应用程序来说,情况就是这样,不知道为什么教程会谈到显示名称。