Created
July 8, 2014 21:14
-
-
Save devilelephant/0bcd66cde78e82282e62 to your computer and use it in GitHub Desktop.
Spring Boot Fix @RequestMapping error on paths with dots or file extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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