Skip to content

Add mvc namespace for simplifying setup of Spring MVC [SPR-6306] #10972

Closed
@spring-projects-issues

Description

@spring-projects-issues

Keith Donald opened SPR-6306 and commented

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>


Affects: 3.0 RC1

Issue Links:

1 votes, 3 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions