REST的复杂URL映射问题求助

发布于 2021-12-05 00:29:48 字数 3961 浏览 926 评论 4

比如这样一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

噩梦成真你也成魔 2021-12-08 17:33:40

楼主怎么解决的?我也遇到这样的问题了!求真相!!!

樱花落人离去 2021-12-07 15:38:48

自己解决了也不说怎么解决的

高跟鞋的旋律 2021-12-07 06:55:20

谢谢,自己已解决!

终止放荡 2021-12-05 09:23:30

/rest/cxf/person/1/hobby/2"  

@Path(value = "/person") 

@Path("/persons/{personId}/hobby/{hobbyId}")

很明显不一样啊.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文