为什么具有相同 URL 但产生不同 MediaType 的 RequestMappings 有效?

问题描述

如果我有相同的 2 requestMapping URL,params(no params) 并生成类型(JSON),我想了解为什么 Spring 应用程序会启动。默认情况下,这些方法正在生成 JSON(我测试了 XML 和其他方法,但出现 500 错误,我没有依赖项。我想知道这是 Intellij 还是 Spring 问题,或者如果我将 Get 放在第二个,那么启动并覆盖第二个 produces = MediaType.APPLICATION_JSON_VALUE 是否正常我也收到错误。这是有效的示例:

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ExampleDTO>> getMethodd1() {
    return ResponseEntity.ok(ExampleStore.available);
}
@GetMapping()
public ResponseEntity<List<ExampleDTO>> getMethodd2() {
    return ResponseEntity.ok(ExampleStore.available);
}

这个例子不再开始:

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ExampleDTO>> getMethodd1() {
    return ResponseEntity.ok(ExampleStore.available);
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ExampleDTO>> getMethodd2() {        
    return ResponseEntity.ok(ExampleStore.available);
}

PS:我知道请求的参数或网址应该不同。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)