我正在编写我的第一个REST应用程序,并从基本的maven archetype org.glassfish.jersey.archetypes jersey_quickstart_webapp 2.16开始。
我创建了一个名为org.anthony.restJersey.messenger的新项目。
除了已定义的内容之外,我没有对此项目进行任何编辑,因为大多数培训都让我设置了tomcat并尝试首先在其上运行webapp。 (我正在关注JavaBrains.koushik.org)。我能够在我的Jave EE Eclipse中运行Tomcat服务器(7.0.52)上的应用程序(版本:Kepler Service Release 2) 构建ID:20140224-0627)。但是,当我尝试点击“泽西资源”链接时,我找不到404。链接为:http://localhost:8080/messenger/webapi/myresource。
下面列出了MyResource.java的默认代码:
package org.anthony.restJersey.messenger;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
@Path("myresource")
public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
}
答案 0 :(得分:1)
在干净的工作区中创建,它工作正常。不确定原始问题。
答案 1 :(得分:0)
(如果您创建了部署在新创建的服务器上的单个项目,则在新工作区中只尝试以下方法) 打开工作区并删除" servers"文件夹以及在eclipse中删除已配置的服务器。重启eclipse并创建新服务器。我认为应该解决这个问题。