Results 1 to 5 of 5

Thread: Mixing XML Configuration and WebMvcConfigurationSupport

  1. #1
    Join Date
    Sep 2012
    Posts
    15

    Default 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 at 01:53 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    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...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2012
    Posts
    15

    Default

    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?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2012
    Posts
    15

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •