How to specify the display of fallback requests in Spring

We have an endpoint that can return different responses depending on the Accept header. In particular, it can return zip files, video files, or audio files.

Display 1:

@RequestMapping(value = "endpoint",
        method = RequestMethod.GET,
        produces = {"video/*", "audio/*"})

Display 2:

@RequestMapping(value = "endpoint",
        method = RequestMethod.GET, produces = {"application/zip", "*/*"})

This setting will take Accept: video/*and go to display 1 (this is what we want). But Accept: video/mp4leads to an exception java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path.

I would suggest that it video/mp4maps mapping 1 more closely and loads it. In fact, this is exactly what we want.

We can delete */*and then Accept: video/mp4go to map 1. However, we need */*to go to map 2.

Why Accept: video/mp4doesn't match 1 because it is a closer match?

, ? 1 , application/zip.

Spring Boot 1.5.3.

+4

Source: https://habr.com/ru/post/1677268/


All Articles