[英]Java EE - Can't find GET method
我有以下资源:
@Path("")
public class ReviewsResource {
@Context
private UriInfo context;
@EJB
private ReviewsReadBeanRemote reviewReadServices;
@EJB
private ReviewsBeanRemote reviewServices;
public ReviewsResource() {
}
@GET
@AuthenticateUser
@Produces({MediaType.APPLICATION_JSON})
@Path("cadets/{id}/reviews")
public Response getApprovedReviewsByCadet(@PathParam("id") Long cadetId)
throws EnviosYaException {
return Response.ok(reviewReadServices.getReviewsByCadet(cadetId, State.APPROVED)).build();
}
@GET
@AuthenticateAdministrator
@Produces({MediaType.APPLICATION_JSON})
@Path("reviews")
public Response getReviews(@QueryParam("state") String state,
@QueryParam("start") Date start, @QueryParam("end") Date end)
throws EnviosYaException {
State stateValue = null;
if (state != null && !state.isEmpty()) {
stateValue = State.valueOf(state);
}
return Response.ok(reviewReadServices.getReviews(stateValue, start, end)).build();
}
@GET
@AuthenticateUser
@Produces({MediaType.APPLICATION_JSON})
@Path("clients/{id}/shipments")
public Response getShipmentsPendingReviewByClient(@PathParam("id") Long clientId)
throws EnviosYaException {
return Response.ok(reviewReadServices.getShipmentsPendingReviewsByClient(clientId)).build();
}
}
我可以像这样很好地使用getReviews
:
https://localhost:8181/Gateway-war/reviews
但是,当我尝试像这样打其他人时:
https://localhost:8181/Gateway-war/cadets/1/reviews
我得到404未找到。
路径有问题吗? 可能是因为我的资源名称吗?
我确实有另一个像这样的资源:
@Path("cadets")
public class CadetsResource {
问题可能出在那里吗?
是的-其他路径正在干扰。 通常,我将每个类的所有服务都放在“名称空间”中。 因此,ReviewsResource可能看起来像:
@Path("/reviews")
public class ReviewsResource {
然后,该类中的所有内容都具有URL的唯一部分。 您已经在CadetsResource类中遵循了该模式-我建议在任何地方都使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.