Java REST服务错误:资源不可用Glassfish 4.0 JAX-RS 2.0
我正在尝试在Glassfish 4.0上部署一个简单的JAX-RS服务,并不断出现以下错误:Java REST服务错误:资源不可用Glassfish 4.0 JAX-RS 2.0,java,rest,jax-rs,glassfish-4,Java,Rest,Jax Rs,Glassfish 4,我正在尝试在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服务器中部署得很好,但是类装入器似乎没有完成它的工作,并且适
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服务器中部署得很好,但是类装入器似乎没有完成它的工作,并且适当地公开了rest服务。我试图弄明白为什么类没有正确加载。我知道这可能是一个简单的配置更改,但我一直无法找到它
配置:
glassfish-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>/reports</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
war是使用/reports的根上下文部署的,我使用的url是:
http://localhost:8080/reports/rest/weeklyStatusReport/run/123
首先,放弃在
web.xml
中编写的所有内容。在GlassFish(以及所有JavaEE7容器)上,JAX-RS可以开箱即用,无需配置
然后在类路径中必须有一个子类javax.ws.rs.core.Application
,声明一个@ApplicationPath(“/”)
(这告诉容器启动JAX-rs引擎)
其他资源将由应用程序服务器自动获取。`您不是在某处注册了web服务类吗?代码在GlassFish 3上起作用了吗?@MarioDennis不可能,这个答案应该用大的闪烁的红色粗体字母突出显示。我不知道有人不需要再乱弄web.xml了!好东西!
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) {
}
}
http://localhost:8080/reports/rest/weeklyStatusReport/run/123