REST的复杂URL映射问题求助
比如这样一个URL:
http://localhost:8080/rest/cxf/person/persons/1/hobby/2
我这样写为什么老是提示404 not found,特来求高人相助!!!!
//不配置@Produces则默认接口返回值数据的MIME类型是application/xml @Path(value = "/person") @Produces({"application/xml"}) public interface PersonService { /** * @Title: queryHobbyOfPepole * @Description: 返回某Person的某个爱好 * @param personId * @param hobbyId * @return */ @GET @Path("/persons/{personId}/hobby/{hobbyId}") public Hobby queryHobbyOfPepole(@PathParam("personId") int personId,@PathParam("hobbyId") int hobbyId); }
@Test public void testGetHobby() { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); String result = service .path("person").path("persons").path("1") .path("hobby").path("2") .accept(MediaType.APPLICATION_XML) .get(String.class); System.out.println(result.toString()); }
2013-12-26 18:13:23 org.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod 警告: No operation matching request path "/rest/cxf/person/1/hobby/2" is found, Relative Path: /1/hobby/2, HTTP Method: GET, ContentType: */*, Accept: application/xml,. Please enable FINE/TRACE log level for more details. 2013-12-26 18:13:23 org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse 警告: javax.ws.rs.ClientErrorException: HTTP 404 Not Found at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:540) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:86) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:287) at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:251) at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:370) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Unknown Source)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
楼主怎么解决的?我也遇到这样的问题了!求真相!!!
自己解决了也不说怎么解决的
谢谢,自己已解决!
/rest/cxf/person/1/hobby/2"
和
@Path(value = "/person")
@Path("/persons/{personId}/hobby/{hobbyId}")
很明显不一样啊.