Announcement Announcement Module
Collapse
No announcement yet.
Mixing XML Configuration and WebMvcConfigurationSupport Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mixing XML Configuration and WebMvcConfigurationSupport

    Hi,

    I needed to extend WebMvcConfigurationSupport in order to replace the default RequestMappingHandlerMapping. However, I still want to use as much XML configuration as possible. It seems that some XML configurations work while others don't. Is mixing XML configurations and WebMvcConfigurationSupport supported/recommended?

    ExtendedWebMvcConfiguration:
    Code:
    @Configuration
    public class ExtendedWebMvcConfiguration extends WebMvcConfigurationSupport {
    
    	@Override
    	@Bean
    	public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    		ExtendedRequestMappingHanderMapping handlerMapping
    				= new ExtendedRequestMappingHanderMapping();
    		handlerMapping.setOrder(0);
    		handlerMapping.setInterceptors(getInterceptors());
    		return handlerMapping;
    	}
    }
    Dispatcher Servlet Context:
    Code:
    	<bean id="extendedWebMvcConfig" class="com.example.ExtendedWebMvcConfiguration" />
    
    	<!-- SEEMS TO WORK -->
    	<mvc:resources mapping="#{resourcesConfig.path}/**" location="/resources/" />
    
    	<!-- DOES NOT SEEM TO WORK -->
    	<mvc:interceptors>
    		<mvc:interceptor>
    			<mvc:mapping path="#{'/test/**'}" />
    			<bean class="com.example.interceptors.TestInterceptor" />
    		</mvc:interceptor>
    	</mvc:interceptors>
    UPDATE: <mvc:interceptors> actually works here. The real problem is that it seems Spring Expressions (#{'/test/**'}) are not evaluated in <mvc:mapping>! Can someone explain why?

    Thanks,
    Andy
    Last edited by achang; Sep 28th, 2012, 02:53 PM.

  • #2
    What isn't working?!

    The interceptors will be set by the framework you don't need to explicitly set them yourself... Also I don't really see why you would need to extend WebMvcConfigurationSupport to simply register your HandlerMapping, simply add it to xml...

    Comment


    • #3
      Marten, thanks for your reply. Sorry I didn't state the reason I needed to replace the default RequestMappingHandlerMapping - I added some custom request mapping conditions which cause the default RequestMappingHandlerMapping to fail. Do you know of any other way to use everything from <mvc:annotation-config/> besides the RequestMappingHandlerMapping?

      Actually, I've looked into this problem a bit more, and I actually misstated my question. You were right, interceptors DO work in my setup.

      The actual problem is Spring Expressions do not work in <mvc:mapping>.

      This works:
      Code:
      	<mvc:interceptors>
      		<mvc:interceptor>
      			<mvc:mapping path="/**" />
      			<bean class="com.example.TestInterceptor" />
      		</mvc:interceptor>
      	</mvc:interceptors>
      This does not work:
      Code:
      	<mvc:interceptors>
      		<mvc:interceptor>
      			<mvc:mapping path="#{'/**'}" />
      			<bean class="com.example.TestInterceptor">
      				<property name="test" value="#{'SUCCEEDED!'}" />
      			</bean>
      		</mvc:interceptor>
      	</mvc:interceptors>
      I set the property "test" to a Spring Expression to test that expressions were being evaluated -- and they were. Can anyone tell me why Spring Expressions do not work in <mvc:mapping /> tags?

      Comment


      • #4
        I would raise a JIRA for that as I doubt it works for anything in the namespace... The namespace fully registers bean definitions and by doing that probably bypass the expression handling.

        Comment


        • #5
          Thanks, I raised an issue:

          https://jira.springsource.org/browse/SPR-9848

          Actually, the resources mapping (<mvc:resources>) does support SpEL but <mvc:mapping> doesn't.

          Comment

          Working...
          X