REST服务错误:资源不可用Glassfish 4.0 JAX-RS 2.0
我试图在Glassfish 4.0上部署一个简单的JAX-RS服务,并继续收到以下错误:
HTTP Status 404 - Not Found type Status report messageNot Found descriptionThe requested resource is not available. GlassFish Server Open Source Edition 4.0
War文件在Glassfish服务器中部署得很好但是看起来类加载器没有正常工作并且正确地公开了其余的服务。 我试图弄清楚为什么课程没有适当加载。 我知道这可能是一个简单的配置更改,但我一直无法找到它。
配置: glassfish-web.xml:
/reports Keep a copy of the generated servlet class' java code.
web.xml中:
Jersey org.glassfish.jersey.servlet.ServletContainer 1 Jersey /rest/* 30
REST服务代码:
package com.esa.report.rest.service; import javax.ws.rs.core.Context; import javax.ws.rs.core.UriInfo; import javax.ws.rs.PathParam; import javax.ws.rs.Consumes; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.enterprise.context.RequestScoped; import javax.ws.rs.core.MediaType; @Path("weeklyStatusReport") @RequestScoped public class WeeklyStatusReportService { @Context private UriInfo context; public WeeklyStatusReportService() { } @GET @Path("run/{esaId}") @Produces({MediaType.APPLICATION_XHTML_XML}) public String runReport(@PathParam("esaId") String esaId){ return("Hello esaId: "+esaId); } @GET @Produces("text/html") public String getHtml() { return("hello this is the weekly status report"); } @PUT @Consumes("text/html") public void putHtml(String content) { } }
使用/ reports的根上下文部署战争,我使用的URL是:
http://localhost:8080/reports/rest/weeklyStatusReport/run/123
首先,丢弃您在web.xml
编写的所有内容。 在GlassFish(以及所有JavaEE 7容器)上,JAX-RS开箱即用,无需配置。
然后你必须在你的类路径中有一个javax.ws.rs.core.Application
子类,声明一个@ApplicationPath("/")
(这告诉容器启动JAX-RS引擎)。
其他资源将由Application Server自动获取