Spring的Jersey始终为子资源提供404
在Spring配置的web服务应用程序中,我有两个简单的资源类。根目录(/reports)工作正常,之后的任何路径都返回404。以下是资源类:Spring的Jersey始终为子资源提供404,spring,rest,jersey,Spring,Rest,Jersey,在Spring配置的web服务应用程序中,我有两个简单的资源类。根目录(/reports)工作正常,之后的任何路径都返回404。以下是资源类: package com.factorlab.ws.reports; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.springframework.be
package com.factorlab.ws.reports;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope("prototype")
@Path("reports")
public class ReportsResource {
@Autowired
private TestItemResource timelineResource;
@Path("testitem")
public TestItemResource getTimelinResource() {
return timelineResource;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getTestText() {
return "Success!\n";
}
}
子资源如下所示:
package com.factorlab.ws.reports;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component
@Scope("prototype")
public class TestItemResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Success!\n";
}
}
我在名为FactoryLab ws的Web应用程序中将应用程序部署到Jetty<代码>卷曲产生成功。然而,curl
给出了404状态
此外,我在ReportsResource中的每个方法中都设置了断点。getTestText()可以很好地中断,但getTimelineResource()不能,这意味着它从未进入该方法
我可能遗漏了什么?我发现了问题所在-它在我的web.xml中。我已经为servlet映射到Jersey Spring servlet配置了几个路径,但这不起作用。我们所做的工作是:
<servlet-mapping>
<servlet-name>jersey-spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
泽西之春
/
我无法得到任何其他映射工作-给我404的一切,除了显式的url模式。所以,这解决了我的问题,但是有人知道这是否是一个bug吗?或者这就是它的工作方式,有什么原因吗?我发现了问题所在——它在我的web.xml中。我已经为servlet映射到Jersey Spring servlet配置了几个路径,但这不起作用。我们所做的工作是:
<servlet-mapping>
<servlet-name>jersey-spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
泽西之春
/
我无法得到任何其他映射工作-给我404的一切,除了显式的url模式。所以,这解决了我的问题,但是有人知道这是否是一个bug吗?或者,这应该是它的工作方式,有什么原因吗?url模式“/”对我不起作用;但是,启用跟踪是有帮助的。url模式“/”对我不起作用;但是,启用跟踪是有帮助的。