【发布时间】:2013-08-31 14:04:34
【问题描述】:
我无法启动我的 REST 服务。我有一个包含我的 service.jar 的 war 文件,在 service.jar 中我的 web 服务包含以下代码
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import se.questify.entities.exam.Question;
@Path("/services/question")
public class QuestionWebService {
@GET
@Path("/ping")
@Produces({MediaType.TEXT_PLAIN})
public String ping() {
return "ping from localhost webservice";
}
}
当它部署到 glassfish 4(我从 eclipse 运行)时,无法在 http://localhost:8080/web/services/question/ping 访问 web 服务(我的上下文根是 /web)。
有人知道为什么这不起作用吗?
Web.xml
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Counter Web Application</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
【问题讨论】:
-
您是否能够访问您的上下文根,即localhost:8080/web?
-
是的,所有其他 html 和 jsf 页面都正常工作
-
那么这意味着您的网络服务映射不正确。你能分享你的web.xml吗?以及您的服务类是如何公开为 REST 的?
-
我添加了 web.xml。你的意思是我需要做更多的事情来公开服务而不是使用路径注释?
-
您使用哪个框架来编写您的 REST 服务?
标签: java web-services rest glassfish-4