Skip to content

Instantly share code, notes, and snippets.

@devilelephant
Created July 8, 2014 21:14
Show Gist options
  • Save devilelephant/0bcd66cde78e82282e62 to your computer and use it in GitHub Desktop.
Save devilelephant/0bcd66cde78e82282e62 to your computer and use it in GitHub Desktop.
Spring Boot Fix @RequestMapping error on paths with dots or file extensions
// I made one of my @Configuration classes extend org.springframework.beans.factory.config.BeanPostProcessor
// There probably is a better way to intecept the ContentNegotiationManager when it is being updated but I couldn't figure out how
// This solved the problems I had better than using the {id:.+} regular expression in path variables idea I've seen on other fixes.
@Override
Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
if (bean instanceof RequestMappingHandlerMapping) {
// handle when dots in url path
def mapping = bean as RequestMappingHandlerMapping
mapping.useSuffixPatternMatch = false
// Separate problem when end of path looks like a common extension
// for example: files/filename.csv
// Luckily Groovy doesn't give a crap about private fields, lol
def manager = mapping.getContentNegotiationManager()
manager.contentNegotiationStrategies.clear()
}
return bean;
}
@Override
Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment