I have a RESTful spring based endpoint to get assets stored in a db to a javascript editor. The relevant parts boil down to:
@RestController
@RequestMapping(
It's not a bug, it's a feature...
As @axtavt and @rhinds have supposed, something is messing around which the content type. The browsers sends a correct Accept: application/json but spring ignores this and uses the extension of the url (aarrgh). From the docs:
16.16.4 Configuring Content Negotiation
You can configure how Spring MVC determines the requested media types from the client for request mapping as well as for content negotiation purposes. The available options are to check the file extension in the request URI, the "Accept" header, a request parameter, as well as to fall back on a default content type. By default, file extension in the request URI is checked first and the "Accept" header is checked next.
The solution is quite simple as you can disable this "feature":
@Configuration
@EnableWebMvc
public class RestCommonsMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
See also Spring does not ignore file extension for xml-config.