Spring 5级介质型弹簧座

Spring 5级介质型弹簧座,spring,rest,domain-driven-design,cqrs,media-type,Spring,Rest,Domain Driven Design,Cqrs,Media Type,我正试图在REST API上应用CQRS原则和域驱动设计原则,使用5个级别的媒体类型,如本文所述: 我的技术背景是SpringRESTFramework版本3.2 基本上,我需要能够使用不同的“域模型”媒体类型映射我的命令。 因此,我希望以下映射能够起作用: @Controller @RequestMapping("resources") public class MyController { @RequestMapping(value = "{id}", method = Requ

我正试图在REST API上应用CQRS原则和域驱动设计原则,使用5个级别的媒体类型,如本文所述:

我的技术背景是SpringRESTFramework版本3.2

基本上,我需要能够使用不同的“域模型”媒体类型映射我的命令。 因此,我希望以下映射能够起作用:

@Controller
@RequestMapping("resources")
public class MyController {

    @RequestMapping(value = "{id}", method = RequestMethod.PUT, consumes = "application/json;domain-model=CommandOne")
    @ResponseBody
    public void commandOne(@PathVariable Long id, @RequestBody CommandOne commandOne) {
        LOG.info("Using command {}", commandOne);
    }

    @RequestMapping(value = "{id}", method = RequestMethod.PUT, consumes = "application/json;domain-model=CommandTwo")
    @ResponseBody
    public void commandTwo(@PathVariable Long id, @RequestBody CommandTwo commandTwo) {
        LOG.info("Using command {}", commandTwo);
    }

}
问题是,我在请求PUT时遇到映射错误:

PUT /resources/123
Content-Type: application/json;domain-model=CommandOne
错误是:

java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path ...
Spring不允许我将相同的uri映射到不同的域模型媒体类型。你知道我怎样才能做到吗?我错过什么了吗

非常感谢
:o)

这是因为内容类型仍然是相同的
application/json
。请看内容类型 作为
domain model=CommandOne
传递的只是一个参数,Spring不认为调用不同的方法有什么区别

这在答案中有更详细的描述

这是提交给Spring团队的一份报告,但他们以“按设计工作”结束

不幸的是,Spring目前无法处理此案例