Announcement Announcement Module
Collapse
No announcement yet.
complete XML for mimicing annotation-driven Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • complete XML for mimicing annotation-driven

    I found the following XML code listing by Keith Donald in Jira-6306 and I wonder if this a complete listing of what <mvc:annotation-driven/> actually does? In other words, will the XML code listing below give the same functionallity as <mvc:annotation-driven/>? The example is related to the Pet Clinic example app and made to illustrate the JIRA. Perhaps it's not fully complete? :
    Code:
    <?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>
    I also found this code from the RapidWeb blog, more extensive with adding messageConverters to the AnnotationMethodHandlerAdapter and somewhat different with a lower order value for instance.
    Code:
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="order" value="0" />
    </bean>
     
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="webBindingInitializer">
            <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                <property name="validator" ref="validator" />
            </bean>
        </property>
        <property name="messageConverters">
            <list>
               <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
               <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
               <bean class="org.springframework.http.converter.FormHttpMessageConverter" />
               <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
            </list>
        </property>
     </bean>
     
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
    <bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
    Also interesting comments about "if JAXB2 is detected on the classpath (it looks for jaxax.xml.bind.Binder), then Jaxb2RootElementHttpMessageConverter is added to the message converter list. If Jackson is detected (it looks for org.codehaus.jackson.map.ObjectMapper and org.codehaus.jackson.JsonGenerator), MappingJacksonHttpMessageConverter is added as well.

    This all happens in the AnnotationDrivenBeanDefinitionParser class."

    I suppose an example application could be made to illustrate the details, which is important to understand as annotation-driven seems to largely be an all or nothing affair.
Working...
X