Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Nov 5, 2009 · 1 comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 5, 2009

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

@spring-projects-issues
Copy link
Collaborator Author

Alex Rau commented

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).

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant