我有一个JAX-RS网络服务,如下所示:
@Path("/service")
public interface Service {
@GET
@Path("/{serviceId}")
public Response getService(@PathParam("serviceId") String serviceId);
@GET
@Path("/{serviceId}/private")
public Response getPrivateService(@PathParam("serviceId") String serviceId);
@GET
@Path("/other-thing")
public Response getOtherThing(@CookieParam("cookieName") String cookieValue);
}
出于某种原因,GET /other-thing
始终使用@Path("/{serviceId}")
调用第一个方法。调用GET /abc/private
返回404声称没有匹配的路由。根据规范,应该选择具有最匹配的文字字符的路径,但似乎我的路线被完全忽略。我该怎么调试呢?
以下是来自CXF的日志消息:
No operation matching request path "/service/abc/private" is found, Relative Path: /abc/private, HTTP Method: GET, ContentType: */*, Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,. Please enable FINE/TRACE log level for more details.
答案 0 :(得分:0)
我发现了这个问题。
我最近从Eclipse切换到IntelliJ。 Eclipse的默认行为是在自动生成接口方法实现时忽略任何注释。另一方面,IntelliJ保留注释。这是不同的:
// In Eclipse
public class ServiceImplementation implements Service {
public Response getService(String serviceId) {
return null;
}
}
// In IntelliJ
public class ServiceImplementation implements Service {
// Note the @PathParam
public Response getService(@PathParam("serviceId") String serviceId) {
return null;
}
}
服务实现中的其他注释会导致路径解析失败。由于我在Eclipse中实现了getService
,它工作正常,但是在我删除服务实现中的参数注释之前,实现IntelliJ的新方法不起作用。