Spring throwing HttpMediaTypeNotAcceptableException: Could not find acceptable representation due to dot in url path [duplicate]
Spring is treating the part after the dot as a file suffix to try to determine what response type you actually want. Here is a decent writeup on content negotiation in Spring.
So what happens is that Spring is trying to present the result to in a content type it can't find a converter to.
To solve this you need to tell spring to turn off suffix-based content negotiation:
@Configurationpublic class ContentNegotiationConfig extends WebMvcConfigurerAdapter { @Override void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { // Turn off suffix-based content negotiation configurer.favorPathExtension(false); }}
Update:
I've dug a bit deeper and I think I can explain what's happening.
The default configuration ignores unknown path suffixes, so to explain this we need to know how Spring determines that a path suffix is unknown and that boils down to this piece of code in PathExtensionContentNegotiationStrategy
:
@Overrideprotected MediaType handleNoMatch(NativeWebRequest webRequest, String extension) throws HttpMediaTypeNotAcceptableException { if (this.useJaf) { MediaType jafMediaType = JafMediaTypeFactory.getMediaType("file." + extension); if (jafMediaType != null && !MediaType.APPLICATION_OCTET_STREAM.equals(jafMediaType)) { return jafMediaType; } } if (!this.ignoreUnknownExtensions) { throw new HttpMediaTypeNotAcceptableException(getAllMediaTypes()); } return null;}
So what's happening is likely that the Java Activation Framework is recognising some of your suffixes and returning a media type for them - the .c extension probably returns text/x-c since that's causing an exception.