如何避免Spring的@RequestMapping路径冲突? [英] How to avoid Spring's @RequestMapping paths conflicts?

查看:85
本文介绍了如何避免Spring的@RequestMapping路径冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Spring定义REST API.我有以下两个@Controller方法:

I'd like to define REST API using Spring. I have these 2 @Controller methods:

@RequestMapping(value = "/{machineId}/workspaces/{workspaceId}", method = RequestMethod.DELETE)
public void removeWorkspace(@PathVariable String machineId, @PathVariable String workspaceId {...}

@RequestMapping(value = "/{machineId}", method = RequestMethod.DELETE)
public void removeVM(@PathVariable String machineId) {...}

问题是,此定义导致路径冲突:如果我尝试调用

The problem is, that this definition causing path conflicts: if I attempt to call

curl -X DELETE http://localhost/machine-1/workspaces/workspace-1

我希望应该调用"removeWorkspace",但是问题是,要调用"removeVM".有人知道如何避免这种冲突吗?{machineId}前缀可能导致此冲突.当然,我想保持这些路径不变.

I would expect, that the "removeWorkspace" should be called, but the problem is, that the "removeVM" is called. Does anybody get idea how to avoid such conflict? {machineId} prefix probably cause this conflict. Of course I'd like to keep those paths unchanged.

谢谢

推荐答案

这是一个错误,同时已在4.1-RC2版本中修复,请参见JIRA

This was a bug fixed meanwhile fixed in version 4.1-RC2, see this JIRA SPR-10576 for further details.

因此,在当前版本中修复此问题的唯一方法似乎是更改URL路径或手动应用补丁.

So it seems the only way to fix it in your current version would be to change the URL paths, or to apply the patch manually.

这篇关于如何避免Spring的@RequestMapping路径冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆