Announcement Announcement Module
Collapse
No announcement yet.
<mvc:annotation-driven/> issues Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <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
    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"/>

    Comment


    • #3
      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.

      Comment

      Working...
      X