Spring Framework
  1. Spring Framework
  2. SPR-6306

Add mvc namespace for simplifying setup of Spring MVC

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0 RC1
    • Fix Version/s: 3.0 RC2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Spring MVC setup could be simplified considerably by adding a custom XML namespace. A simple tag to configure <mvc:annotated-controllers/> with reasonable default settings would be a great start.

      Example benefits:

      AFTER MVC NAMESPACE

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:mvc="http://www.springframework.org/schema/mvc"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	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.0.xsd">
      
      	<mvc:annotation-driven/>
      	
      </beans>
      
      

      BEFORE MVC NAMESPACE

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xsi:schemaLocation="
      		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
      
      	<!-- HANDLER MAPPING RULES -->
      	
      	<!-- Maps requests to @Controllers based on @RequestMapping("path") annotation values
      		 If no annotation-based path mapping is found, Spring MVC sends a 404 response and logs a pageNotFound warning. -->
      	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
      		<property name="order" value="1" />
      	</bean>
      	
      	<!-- REGISTERED HANDLER TYPES -->
      
      	<!-- Enables annotated @Controllers; responsible for invoking an annotated POJO @Controller when one is mapped. -->
      
      	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
      		<!-- Configures Spring MVC DataBinder instances globally -->
      		<property name="webBindingInitializer">
      			<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
      				<property name="conversionService" ref="conversionService" />
      				<property name="validator" ref="validator" />
      			</bean>
      		</property>
      	</bean>
      
      	<!-- FIELD TYPE CONVERSION AND VALIDATION -->
      	
      	<!-- Enables the Spring 3 Type Conversion system that uses Joda Time Formatting for Date/Time types -->
      	<bean id="conversionService" class="org.springframework.samples.petclinic.util.PetclinicConversionServiceFactory" />
      	
      	<!-- Configures JSR-303 Declarative Validation with default provider on classpath (Hibernate Validator) -->
      	<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
      	
      </beans>
      
      

        Issue Links

          Activity

          Hide
          Alex Rau added a comment -

          I think this feature breaks or at least is not conforming to the implemented strategy in MVC that there is an implicit DefaultAnnotationHandlerMapping (D1) which can be replaced with custom parameterized versions (D2) of handler mappings.

          As soon as someone wants to use the above short-cut "<mvc:annotation-driven>" there will be a DefaultAnnotationHandlerMapping (D3) which a) cannot be replaced with a custom version (D2) anymore and b) replaces the implicit one (D1). Even worse - developers declaring (D3) assuming they would override the implicit one (D1) will end up with two instances of DefaultAnnotationHandlerMapping (D2 and D3) resulting in duplicate registration of annotated controllers (component scan) and custom parameterization which will be without any effect as D2 seems to win over D3.

          I think at least a dedicated property for the above declaration should be defined which allows passing in a custom DefaultAnnotationHandlerMapping along with the declaration (+ some clarifying documentation about this wouldn't be too bad).

          Show
          Alex Rau added a comment - I think this feature breaks or at least is not conforming to the implemented strategy in MVC that there is an implicit DefaultAnnotationHandlerMapping (D1) which can be replaced with custom parameterized versions (D2) of handler mappings. As soon as someone wants to use the above short-cut "<mvc:annotation-driven>" there will be a DefaultAnnotationHandlerMapping (D3) which a) cannot be replaced with a custom version (D2) anymore and b) replaces the implicit one (D1). Even worse - developers declaring (D3) assuming they would override the implicit one (D1) will end up with two instances of DefaultAnnotationHandlerMapping (D2 and D3) resulting in duplicate registration of annotated controllers (component scan) and custom parameterization which will be without any effect as D2 seems to win over D3. I think at least a dedicated property for the above declaration should be defined which allows passing in a custom DefaultAnnotationHandlerMapping along with the declaration (+ some clarifying documentation about this wouldn't be too bad).

            People

            • Assignee:
              Keith Donald
              Reporter:
              Keith Donald
              Last updater:
              Trevor Marshall
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                4 years, 19 weeks, 5 days ago