我想在我的REST API和領域驅動設計原則也適用CQRS的原則,採用5級媒體類型,在這些文章中解釋說: https://www.infoq.com/articles/rest-api-on-cqrs http://byterot.blogspot.ch/2012/12/5-levels-of-media-type-rest-csds.html5級媒體類型的彈簧安置
我的技術環境是Spring REST框架版本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不允許我映射不同的域模型媒體類型。任何想法我怎麼能做到這一點?我錯過了什麼嗎?
非常感謝 :O)