Skip to content

Instantly share code, notes, and snippets.

Created February 7, 2014 22:50
Show Gist options
  • Save MikeN123/8873622 to your computer and use it in GitHub Desktop.
Save MikeN123/8873622 to your computer and use it in GitHub Desktop.
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.PriorityOrdered;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
* This postprocessor sets {@code useSuffixPatternMatch} and {@code useTrailingSlashMatch} to {@code false}, so we have
* exact URL matching. This prevents 404's, wrong base URL's, and automatic matching on extensions (.json), which is
* useful when using {@code PathParam}s.
* @author David Melia
* @author Erik van Paassen
* @see <a href="">SPR-9371: Cannot amend properties in
* RequestMappingHandlerMapping (e.g. useSuffixPatternMatch)...</a>
* @see <a href="">SPR-10163: Make it super-easy to configure the
* RequestMappingHandlerMapping via XML</a>
public class MvcConfigurationPostProcessor implements BeanPostProcessor, PriorityOrdered {
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RequestMappingHandlerMapping) {
RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) bean;
// URL decode after request mapping, not before.
// Workaround to make the previous fix work. See
return bean;
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment