-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
David Melia opened SPR-9371 and commented
Hi,
I want to change the behaviour of RequestMappingHandlerMapping.useSuffixPatternMatch from true to false and keep the neat mvc xml namespace configuration. In the Spring document (Section 16.14.9 Advanced Customizations with the MVC Namespace) it states I can do this using a bean post processor however I don't believe this is the case.
The following is my post processor
public class MvcConfigurationPostProcessor implements BeanPostProcessor, PriorityOrdered {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RequestMappingHandlerMapping) {
((RequestMappingHandlerMapping) bean).setUseSuffixPatternMatch(false);
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
}
}
and my simple spring config
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.beanprocbug.melia" />
<bean class="com.beanprocbug.melia.MvcConfigurationPostProcessor" />
<mvc:annotation-driven />
</beans>
and my test
package com.beanprocbug.melia;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@ContextConfiguration(locations = { "/spring-test.xml" })
public class BugTest extends AbstractJUnit4SpringContextTests {
@Test
public void test() {
// ApplicationContextAwareProcessor gets fired first
}
}
and the problem appears to be because ApplicationContextAwareProcessor always has high priority (which makes sense) then initApplicationContext in the RequestMappingHandlerMapping parent class causes some eager initialisation which uses the flag useSuffixPatternMatch before my bean post processor gets change to change it.
I believe the only way I can get around this is ditch the mvc xml configuration and use WebMvcConfigurationSupport however this is undesireable and the documentation does suggest I should be able to use a Bean post processor.
Many Thanks
David Melia
Affects: 3.1.1
Sub-tasks:
- Backport "Cannot amend properties in RequestMappingHandlerMapping (e.g. useSuffixPatternMatch) using a bean post processor as ApplicationContextAwareProcessor always fires first initialising RequestMappingHandlerMapping" [SPR-9396] #14032 Backport "Cannot amend properties in RequestMappingHandlerMapping (e.g. useSuffixPatternMatch) using a bean post processor as ApplicationContextAwareProcessor always fires first initialising RequestMappingHandlerMapping"
Referenced from: commits e7b44e0, 3b4210f, 5e4f3b3, d7efc0d, 23fe1e2