Results 1 to 3 of 3

Thread: <mvc:annotation-driven/> issues

  1. #1

    Default <mvc:annotation-driven/> issues

    We need to use <mvc:annotation-driven/> in our project to support JSR 303 validations. At the same time we need to extend org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter and override protected HttpInputMessage createHttpInputMessage.

    Code:
    public class AnnotationMethodHandlerAdapter extends org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 
    {
        
    	public AnnotationMethodHandlerAdapter() {
    		System.out.println("In mY custom handler");
    	}
    	
    	@Override
    	protected HttpInputMessage createHttpInputMessage(HttpServletRequest servletRequest) throws Exception {
    		return new ServletServerHttpRequest(servletRequest);
    	}
    
       
    }
    Using <mvc:annotation-driven/> prevents from from doing so. I looked the source code for <mvc:annotation-driven/> (AnnotationDrivenBeanDefinitionParser.java) at it looks like they always create an instance of AnnotationMethodHandlerAdapter which prevents the spring container from using my custom AnnotationMethodHandlerAdapter

    Has anyone faced similar issues

  2. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    Just define the beans yourself and don't use <mvc:annotation-driven/>.

    Code:
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="webBindingInitializer">
            <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                <property name="conversionService" ref="conversionService" />
                <property name="validator" ref="validator" />
            </bean>
        </property>
    </bean>
    
    <!-- Configures JSR-303 Declarative Validation with default provider on classpath (Hibernate Validator) -->
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
    
    <!-- Configures JSR-303 Declarative Validation with default provider on classpath (Hibernate Validator) -->
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>

  3. #3
    Join Date
    Oct 2009
    Location
    Minneapolis, MN
    Posts
    137

    Default

    In your config xml file define your custom AnnotationXXXX bean definition before you use <mvc:annotation-driven/> tag. That way it will register your adaptor.

Posting Permissions

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